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

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
worldaway
Prole
Posts: 44
Joined: Thu Sep 08, 2011 2:22 am

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

Post 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.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

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

Post 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() )
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
worldaway
Prole
Posts: 44
Joined: Thu Sep 08, 2011 2:22 am

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

Post 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?
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

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

Post 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)
worldaway
Prole
Posts: 44
Joined: Thu Sep 08, 2011 2:22 am

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

Post 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?
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

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

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 98 guests