Page 1 of 1

How do i load an image onto a player with physics?

Posted: Thu Sep 08, 2011 2:31 am
by worldaway
I followed the physics tutorial: http://love2d.org/wiki/Tutorial:Physics
and i want to change the red circle to a smiley face. the coding for physics is different than the hampser ball tutorial coding, so i can't do love.graphics.newImage! someone please tell me how to do this.

thanks.

Re: How do i load an image onto a player with physics?

Posted: Thu Sep 08, 2011 3:14 am
by Taehl
You do still use love.graphics.newImage, just like the hampster ball tutorial. The only difference is, you have to draw it at the coordinates of the physics body. So the code would be like this:

Code: Select all

 love.graphics.love.graphics.draw( hamster, objects.ball.body:getX(), objects.ball.body:getY() )

Re: How do i load an image onto a player with physics?

Posted: Thu Sep 08, 2011 4:23 am
by worldaway
Taehl wrote:You do still use love.graphics.newImage, just like the hampster ball tutorial. The only difference is, you have to draw it at the coordinates of the physics body. So the code would be like this:

Code: Select all

 love.graphics.love.graphics.draw( hamster, objects.ball.body:getX(), objects.ball.body:getY() )
ohhhh ok thanks. that goes under function love.draw() right?

Re: How do i load an image onto a player with physics?

Posted: Thu Sep 08, 2011 4:32 am
by slime
Taehl wrote:You do still use love.graphics.newImage, just like the hampster ball tutorial. The only difference is, you have to draw it at the coordinates of the physics body. So the code would be like this:

Code: Select all

 love.graphics.love.graphics.draw( hamster, objects.ball.body:getX(), objects.ball.body:getY() )

Code: Select all

local b = objects.ball.body
love.graphics.draw(hamster, b:getX(), b:getY(), b:getAngle(), 1, 1, hamster:getWidth()/2, hamster:getHeight()/2)

Re: How do i load an image onto a player with physics?

Posted: Fri Sep 09, 2011 1:53 am
by worldaway
slime wrote:
Taehl wrote:You do still use love.graphics.newImage, just like the hampster ball tutorial. The only difference is, you have to draw it at the coordinates of the physics body. So the code would be like this:

Code: Select all

 love.graphics.love.graphics.draw( hamster, objects.ball.body:getX(), objects.ball.body:getY() )

Code: Select all

local b = objects.ball.body
love.graphics.draw(hamster, b:getX(), b:getY(), b:getAngle(), 1, 1, hamster:getWidth()/2, hamster:getHeight()/2)
I tried that and got:
Error
main.lua:49: attempt to index global 'object'(a nil value)

help?

Re: How do i load an image onto a player with physics?

Posted: Fri Sep 09, 2011 2:03 am
by TechnoCat
worldaway wrote:
slime wrote:

Code: Select all

local b = objects.ball.body
love.graphics.draw(hamster, b:getX(), b:getY(), b:getAngle(), 1, 1, hamster:getWidth()/2, hamster:getHeight()/2)
I tried that and got:
Error
main.lua:49: attempt to index global 'object'(a nil value)

help?
object ~= objects