mouse direction

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
IAsep-TrixI
Citizen
Posts: 89
Joined: Mon Aug 12, 2013 4:22 am
Location: Philippines,Asia

mouse direction

Post 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)
An agent of the free

check out the game I'm doing with Jkash!
User avatar
DaedalusYoung
Party member
Posts: 407
Joined: Sun Jul 14, 2013 8:04 pm

Re: mouse direction

Post 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
User avatar
IAsep-TrixI
Citizen
Posts: 89
Joined: Mon Aug 12, 2013 4:22 am
Location: Philippines,Asia

Re: mouse direction

Post 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
?
An agent of the free

check out the game I'm doing with Jkash!
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: mouse direction

Post by Roland_Yonaba »

Yes.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: mouse direction

Post by Robin »

[wiki]love.mousepressed[/wiki]
Help us help you: attach a .love.
User avatar
IAsep-TrixI
Citizen
Posts: 89
Joined: Mon Aug 12, 2013 4:22 am
Location: Philippines,Asia

Re: mouse direction

Post 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!
An agent of the free

check out the game I'm doing with Jkash!
User avatar
IAsep-TrixI
Citizen
Posts: 89
Joined: Mon Aug 12, 2013 4:22 am
Location: Philippines,Asia

Re: mouse direction

Post 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?
An agent of the free

check out the game I'm doing with Jkash!
User avatar
DaedalusYoung
Party member
Posts: 407
Joined: Sun Jul 14, 2013 8:04 pm

Re: mouse direction

Post 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.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: mouse direction

Post 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.
User avatar
IAsep-TrixI
Citizen
Posts: 89
Joined: Mon Aug 12, 2013 4:22 am
Location: Philippines,Asia

Re: mouse direction

Post 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
An agent of the free

check out the game I'm doing with Jkash!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 83 guests