Page 1 of 1

mouse position problem

Posted: Mon Apr 24, 2017 2:40 am
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

Re: mouse position problem

Posted: Mon Apr 24, 2017 5:42 am
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 ().

Re: mouse position problem

Posted: Mon Apr 24, 2017 11:03 am
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...

Re: mouse position problem

Posted: Mon Apr 24, 2017 1:22 pm
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

Re: mouse position problem

Posted: Mon Apr 24, 2017 10:13 pm
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.