Page 1 of 2
mouse direction
Posted: Sun Oct 27, 2013 10:29 pm
by IAsep-TrixI
I was just wondering, how to check the mouse direction, because for my new game that Im working on in my spare time, he will look left and right when either A or D is pressed, but what I want him to do is that when my mouse is on the left or right from the middle of the screen and I click, it will face the direction of the mouse (not rotate just normal left and right direction)
Re: mouse direction
Posted: Sun Oct 27, 2013 11:14 pm
by DaedalusYoung
Code: Select all
if mouse.x < screen.width / 2 then
-- mouse is on the left half of the screen
else
-- mouse is on the right half of the screen
end
Re: mouse direction
Posted: Sun Oct 27, 2013 11:57 pm
by IAsep-TrixI
DaedalusYoung wrote:Code: Select all
if mouse.x < screen.width / 2 then
I only want it to update when the mouse is clicked, should I do something like
If mouse is clicked then
if mouse.x < screen.width/2 then
blah blahb lah
end
end
?
Re: mouse direction
Posted: Mon Oct 28, 2013 12:21 am
by Roland_Yonaba
Yes.
Re: mouse direction
Posted: Mon Oct 28, 2013 11:45 am
by Robin
[wiki]love.mousepressed[/wiki]
Re: mouse direction
Posted: Mon Oct 28, 2013 11:09 pm
by IAsep-TrixI
DaedalusYoung wrote:Code: Select all
if mouse.x < screen.width / 2 then
-- mouse is on the left half of the screen
else
-- mouse is on the right half of the screen
end
It worked! It kinda didnt work right, so I tweaked it a bit to my likings so instead of screenWidth it is not player.x so that it goes left/right according to the players location
Thanks for the help guys!
Re: mouse direction
Posted: Tue Oct 29, 2013 11:48 am
by IAsep-TrixI
DaedalusYoung wrote:Code: Select all
if mouse.x < screen.width / 2 then
-- mouse is on the left half of the screen
else
-- mouse is on the right half of the screen
end
It worked at first but when I started using tiled and the camera lib it started to mess up, do you know whats causing this?
Re: mouse direction
Posted: Tue Oct 29, 2013 9:17 pm
by DaedalusYoung
I've never used any libs, so I can only guess. The camera lib might change the mouse position value based on scale/translation/rotation.
Re: mouse direction
Posted: Tue Oct 29, 2013 10:38 pm
by Plu
Most likely the mouse is using screen coördinates, while the player is using world coördinates. There is most likely a function to convert between the two in the library; make sure both are using the same coördinate system.
Re: mouse direction
Posted: Wed Oct 30, 2013 8:49 pm
by IAsep-TrixI
Plu wrote:Most likely the mouse is using screen coördinates, while the player is using world coördinates.
I was doing
Code: Select all
if mouse.x > player.x then
blah blah blah
end
it used the players coordinates to switch directions when the mouse is clicked