[SOLVED]Problem with love.mousepressed

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.
Post Reply
Ekamu
Party member
Posts: 178
Joined: Fri Sep 20, 2013 11:06 am

[SOLVED]Problem with love.mousepressed

Post by Ekamu »

I have an image named p.png, its 32x32 pixels
Its position is the center of the screen at
posx = 400- 16 --x co-ordinate
posy = 300 - 16 --y co-ordinate

I chucked some stuff in the love.update so that when I click somewhere the position is updated and the image p.png is drawn where I clicked.

Code: Select all

-- this is the start up script
function love.load() 
pos = love.graphics.newImage("p.png")
love.graphics.setBackgroundColor(0,0,0)
posx = 400 - 16
posy = 300 - 16
end

function love.update(dt)
    function love.mousepressed(x,y,button)
        if button == "1" then
	    posx = x
	    posy = y
	    end
    end
        function love.draw()
            love.graphics.draw(pos,posx,posy)
        end
end
Nothing happens, instead it just drawn the image continuously. Was I wrong for chucking stuff inside love.update?

How else can you continuously check for input, it made sense that you will need to do that sort of thing in an update script.

Thanks, I'm sure its some small glitch somewhere though...
Last edited by Ekamu on Fri Oct 04, 2013 6:01 pm, edited 1 time in total.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Problem with love.mousepressed

Post by Plu »

love.mousepressed is an event, it goes outside of the love.update. You don't have to continuously check for input, LÖVE does that for you and will call love.mousepressed as soon as it detects any.

Also mouse.button should be a lowercase letter L not a 1.

Likewise your love.draw function should be outside of the love.update function, LÖVE will call love.draw automatically.
User avatar
Sheepolution
Party member
Posts: 264
Joined: Mon Mar 04, 2013 9:31 am
Location: The Netherlands
Contact:

Re: Problem with love.mousepressed

Post by Sheepolution »

And you're actually not supposed to put love.draw() inside love.update. LÖVE will repeat draw by itself.
Ekamu
Party member
Posts: 178
Joined: Fri Sep 20, 2013 11:06 am

Re: Problem with love.mousepressed

Post by Ekamu »

Ahah I knew it was a minor glitch!
Thanks, it works fine. I used ONE instead of lower case L

Good to know Love handles input checking and drawing without having to set up a manual update loop. I always hated that part.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 75 guests