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!
Calculate mouse movement without mouse position?
- monsieur_h
- Citizen
- Posts: 69
- Joined: Tue Oct 30, 2012 4:43 pm
Re: Calculate mouse movement without mouse position?
It's not clear to me, could you illustrate?tomshreds wrote:Hi,
I'm trying to put object on a map by dragging them on a map.
You could use
Code: Select all
love.mouse.setGrab( true )
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
Re: Calculate mouse movement without mouse position?
I already set setGrab to true right at the beginning of my love.load.monsieur_h wrote: You could usedon't you?Code: Select all
love.mouse.setGrab( true )
Annnnnd your little cheat helped me because now it works! THANKS!
- monsieur_h
- Citizen
- Posts: 69
- Joined: Tue Oct 30, 2012 4:43 pm
Re: Calculate mouse movement without mouse position?
Haha, you're welcome. I threw it completly randomly. Didn't think it would help. Don't hesitate to show off the result!
Re: Calculate mouse movement without mouse position?
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 ;-)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!
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!
Re: Calculate mouse movement without mouse position?
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.
Without the hacky code, it's just the mx,my=love.mouse.getPosition.
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
Lua is not an acronym.
Who is online
Users browsing this forum: No registered users and 2 guests