Page 1 of 1

[SOLVED]Need help: I want to print x and y position of mouse

Posted: Thu Sep 04, 2014 1:33 pm
by nice
Hello boys and girls!

This is a pretty small question but it has been scratching my brain for far too long.
I want to print the X and Y position of the mouse on the Löve/lua screen, I have been lurking around on the wiki and reading love.mouse functions and love.print but none of them helps me understand properly.
I have done this before but for various reasons I haven't touched lua for a while and I need some help to get the wheels rolling.

Thank you for using your time and helping me!

Re: Need help: I want to print x and y position of mouse

Posted: Thu Sep 04, 2014 1:36 pm
by Robin
The relevant functions are [wiki]love.mouse.getPosition[/wiki] and [wiki]love.graphics.print[/wiki]. What do you have so far?

Re: Need help: I want to print x and y position of mouse

Posted: Thu Sep 04, 2014 1:48 pm
by nice
I have function love.mouse() set up and I'm looking at the love.mouse.getPosition but even then I don't really understand, I know that you need love.print in here but again I still don't understand where I should where mouse.getPosition should be in there..

Re: Need help: I want to print x and y position of mouse

Posted: Thu Sep 04, 2014 2:04 pm
by Robin
Please upload a .love, as per the rules, because it's not clear what you have right now.

Also, love.mouse is not a function or a callback. It is a module. If you override it with a function, it's not going to work.

Re: Need help: I want to print x and y position of mouse

Posted: Thu Sep 04, 2014 2:09 pm
by nice
Sorry about that, I'm not very used to the forum thing..
And as requested here's my main.lua file

Re: Need help: I want to print x and y position of mouse

Posted: Thu Sep 04, 2014 4:41 pm
by Robin
Right. That's not a .love, but close enough.

Add

Code: Select all

local x, y = love.mouse.getPosition()
love.graphics.print("mouse x is: " .. x, 10, 10)
love.graphics.print("mouse y is: " .. y, 10, 40)
to the top of love.draw().

The first line gets the position of the mouse. The second and third line print the position to the screen.

Also, remove this:

Code: Select all

function love.mouse()

end
Once again, love.mouse is a module, not a callback function like love.draw!

Re: Need help: I want to print x and y position of mouse

Posted: Thu Sep 04, 2014 4:54 pm
by nice
Thank you so much for your help, I really needed it!
I will remember this till next time.