Page 1 of 1
Physics and images (HardonCollider)
Posted: Sat Jan 14, 2012 11:26 pm
by Jeen
Hello.
I use HardonCollider for collision detection and it works pretty good. But I need to draw a player sprite and move it with its bounding box together. How can I do this?
Thank you
.
Re: Physics and images (HardonCollider)
Posted: Sun Jan 15, 2012 12:19 am
by tentus
Probably the easiest way would be to use
shape:center() to get the shape center and use the numbers returned to draw the sprite at the right place.
Re: Physics and images (HardonCollider)
Posted: Sun Jan 15, 2012 1:29 am
by Jeen
Thanks, it works, but the sprite draws at left-bottom corner of the bounding box. How can I fix it? Also, if I try to add other arguments to love.graphics.draw, the sprite doesn't move down with the box, only on x axis.
Code: Select all
function love.draw()
love.graphics.draw(heroImage, hero:center(x))
end
hero is:
Code: Select all
hero = collider:addRectangle(x,y,16,16)
Re: Physics and images (HardonCollider)
Posted: Sun Jan 15, 2012 1:44 am
by tentus
Code: Select all
function love.draw()
local hx, hy = hero:center()
love.graphics.draw(heroImage, hx - 8, hy - 8)
end
(The negative 8 is 1/2 your hero's width and height.)
Re: Physics and images (HardonCollider)
Posted: Sun Jan 15, 2012 10:58 am
by bartbes
You're probably better off using the origin arguments (ox and oy), because they correctly handle rotation as well.