mouse position problem

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
PGUp
Party member
Posts: 105
Joined: Fri Apr 21, 2017 9:17 am

mouse position problem

Post by PGUp »

hi, so i am a beginner here, and i have some problems with mouse position,
so, let say i am trying to do this:

love.draw()
love.graphics.print(love.mouse.getX)
end

well, it wont work.. ive see the documentation and i think i dont really understand, can anyone explain about it ? i am trying to get the mouse position so i can make an object position same with the mouse position
-
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Re: mouse position problem

Post by veethree »

Try this

Code: Select all

love.graphics.print(love.mouse.getX())
love.mouse.getX is a function, You need to end it with ().
PGUp
Party member
Posts: 105
Joined: Fri Apr 21, 2017 9:17 am

Re: mouse position problem

Post by PGUp »

veethree wrote: Mon Apr 24, 2017 5:42 am Try this

Code: Select all

love.graphics.print(love.mouse.getX())
love.mouse.getX is a function, You need to end it with ().
oh ok, i tried it using a variable like
mousepos = love.mouse.getX()
and print the mousepos.. it works, but the number wont change when i move the mouse...
-
User avatar
OnACoffeeBreak
Prole
Posts: 28
Joined: Tue Apr 11, 2017 11:19 am

Re: mouse position problem

Post by OnACoffeeBreak »

but the number wont change when i move the mouse
Try this as your whole main.lua program. Printed values will update when the mouse cursor is inside the game window:

Code: Select all

function love.draw()
  mousepos_x = love.mouse.getX()
  mousepos_y = love.mouse.getY()
  love.graphics.print(mousepos_x .. ", " .. mousepos_y, 100, 100)
end
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Re: mouse position problem

Post by veethree »

PGUp wrote: Mon Apr 24, 2017 11:03 am
veethree wrote: Mon Apr 24, 2017 5:42 am Try this

Code: Select all

love.graphics.print(love.mouse.getX())
love.mouse.getX is a function, You need to end it with ().
oh ok, i tried it using a variable like
mousepos = love.mouse.getX()
and print the mousepos.. it works, but the number wont change when i move the mouse...
You're probably calling "mousepos = love.mouse.getX()" in love.load or outside a function. For it to update you need to put it inside love.update or love.draw. Those are called once every frame.
Post Reply

Who is online

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