Calculate mouse movement without mouse position?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
tomshreds
Party member
Posts: 101
Joined: Thu Oct 18, 2012 8:49 pm

Calculate mouse movement without mouse position?

Post by tomshreds »

Hi,

I'm trying to put object on a map by dragging them on a map.

The problem is, when I go away from the game window borders, it stops moving.

So I thought about calculating coordinates based on mouse movement.

But once the mouse cursor has arrived on the edge of the screen I'm stuck since coordinates stay the same even if I "move" the mouse.

Any way of calculating mouse movement without using mouse position? I mean since the cursor ends in the corner of the screen, its position doesn't change so I must find a way to calculate the movement anyway if the user tries to position something on the map. (The cursor is invisible, and setGrab = true)

This happen right now because the game's gridsize is 48 and I move object by 24 to make more possibilities of placement. So the mouse gets to half of the screen and then stops since the cursor is on the screen's edge.

I don't know if I explain this clearly, any questions are welcome.

EDIT: I could try to calculate mouse acceleration and use this to move faster/slower in the game window (while placing object only), any idea about mouse acceleration?

Thanks!
User avatar
monsieur_h
Citizen
Posts: 69
Joined: Tue Oct 30, 2012 4:43 pm

Re: Calculate mouse movement without mouse position?

Post by monsieur_h »

tomshreds wrote:Hi,

I'm trying to put object on a map by dragging them on a map.
It's not clear to me, could you illustrate?
You could use

Code: Select all

love.mouse.setGrab( true )
don't you?

Or either "cheat" with this:

Code: Select all


-- In you update code
local x,y = love.mouse.getPosition()
if x < 0 then
x=love.graphics.getWidth()
elseif x>=love.graphics.getWidth() then
x=0
end

if x < 0 then
y=love.graphics.getHeight()
elseif y>=love.graphics.getHeight() then
y=0
end
But once again, a further explanation could be useful.
tomshreds
Party member
Posts: 101
Joined: Thu Oct 18, 2012 8:49 pm

Re: Calculate mouse movement without mouse position?

Post by tomshreds »

monsieur_h wrote: You could use

Code: Select all

love.mouse.setGrab( true )
don't you?
I already set setGrab to true right at the beginning of my love.load.

Annnnnd your little cheat helped me because now it works! THANKS!
User avatar
monsieur_h
Citizen
Posts: 69
Joined: Tue Oct 30, 2012 4:43 pm

Re: Calculate mouse movement without mouse position?

Post by monsieur_h »

Haha, you're welcome. I threw it completly randomly. Didn't think it would help. Don't hesitate to show off the result!
tomshreds
Party member
Posts: 101
Joined: Thu Oct 18, 2012 8:49 pm

Re: Calculate mouse movement without mouse position?

Post by tomshreds »

monsieur_h wrote:Haha, you're welcome. I threw it completly randomly. Didn't think it would help. Don't hesitate to show off the result!
Actually you can see the results! I just pushed a new alpha build for my game Indie Game Story. Just register on the forums to be "alpha tester" and download the latest release ;-)

http://forums.indiegamestory.org/

If you want to know more I'm fundraising on Indiegogo right now:
http://www.indiegogo.com/indiegamestory/x/1720837

I guess I should post a thread about that for fellow lovers who'd like to help a real project that will release on Steam (working very hard on it!)

Thanks!
User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: Calculate mouse movement without mouse position?

Post by qaisjp »

hey,
i just tried this (the cheating way) and it doesn't work as expected. i am using setGrab, here's the code I'm using - please help me.

Code: Select all

local mousex, mousey = love.mouse.getPosition()
local lastMouseUpdate = os.clock()
function game_update(dt)
	-- hacky mouse position code to make a "borderless" game
	local mx,my = love.mouse.getPosition()
	if mx < 0 then
		mx = love.graphics.getWidth()
	elseif mx >= love.graphics.getWidth() then
		mx = 0
	end
	if mx < 0 then
		my = love.graphics.getHeight()
	elseif my >= love.graphics.getHeight() then
		my = 0
	end

	if (mousex~=mx) or (mousey~=my) then
		if ( math.abs(mousex-mx) > 2 ) or ( math.abs(mousey-my) > 2) then
			mousex, mousey = mx, my
			lastMouseUpdate = os.clock()
		end
	end


        ... stuff and some stuff that uses mousex and mousey
end
Without the hacky code, it's just the mx,my=love.mouse.getPosition.
Lua is not an acronym.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests