Issue #470 new

love.mouse.getRelativePosition

criptych avatarcriptych created an issue

(Possibly related to #74 and/or #399)

I'm working on a project that I would like to use FPS-style controls, i.e. continuous mouse movement in any direction. The traditional solution to this in SDL is to grab input and hide the cursor (respectively setGrab and setVisible in LOVE) - but LOVE doesn't have a way to get relative mouse motion, and the (invisible) cursor stops when it reaches the edge of the window, so taking deltas is out of the question as well.

Mouse motion events have already been ruled out I see, but it would be nice to at least have a "getRelativePosition" function, with the caveat that it should only be called once per frame.

This is personally a "blocker" issue for me right now, but I realize in the grand scheme of things it's pretty minor...

Comments (3)

  1. Boolsheet

    I don't have anything regarding the issue itself, but if you consider this a blocker, I can suggest a workaround. The mouse movement still only goes to the window edge and if you expect large movements it probably will feel weird to the player.

    local x, y = 0, 0
    function love.update(dt)
    	local mx, my = love.mouse.getPosition()
    	love.mouse.setPosition(400, 300)
    	x, y = x + (mx - 400)*0.2, y + (my - 300)*0.2
    end
    
    function love.draw()
    	q:setViewport(-x, -y, 2000, 2000)
    	love.graphics.drawq(img, q, 0, 0)
    end
    
    function love.keypressed(k)
    	if k == "escape" then
    		love.event.quit()
    	end
    end
    
    function love.load()
    	local imgData = love.image.newImageData(64, 64)
    	for x = 0, 63 do
    		imgData:setPixel(x, 0, 255, 255, 255, 255)
    		imgData:setPixel(0, x, 255, 255, 255, 255)
    	end
    	img = love.graphics.newImage(imgData)
    	img:setWrap("repeat", "repeat")
    	q = love.graphics.newQuad(0, 0, 1000, 1000, img:getWidth(), img:getHeight())
    end
    

    Does this work for you? I didnt' make the cursor invisible, it should work even better then.

  2. criptych

    Thanks for the suggestion. Long-term, it's not ideal (then again, I'm a perfectionist), but I think this'll work for what I need. Maybe I'm just too used to SDL_GetRelativeMouseState.

    P.S. It seems to work just fine whether the cursor is visible or not. The main difference seems to be that you don't need to setGrab(true).

  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.