Physics and images (HardonCollider)

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
Jeen
Prole
Posts: 2
Joined: Sat Jan 14, 2012 11:24 pm

Physics and images (HardonCollider)

Post 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 :3.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Physics and images (HardonCollider)

Post 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.
Kurosuke needs beta testers
Jeen
Prole
Posts: 2
Joined: Sat Jan 14, 2012 11:24 pm

Re: Physics and images (HardonCollider)

Post 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)
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Physics and images (HardonCollider)

Post 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.)
Kurosuke needs beta testers
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Physics and images (HardonCollider)

Post by bartbes »

You're probably better off using the origin arguments (ox and oy), because they correctly handle rotation as well.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests