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 .
Jeen
Prole
Posts: 2 Joined: Sat Jan 14, 2012 11:24 pm
Post
by Jeen » Sat Jan 14, 2012 11:26 pm
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
.
tentus
Inner party member
Posts: 1060 Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:
Post
by tentus » Sun Jan 15, 2012 12:19 am
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.
Jeen
Prole
Posts: 2 Joined: Sat Jan 14, 2012 11:24 pm
Post
by Jeen » Sun Jan 15, 2012 1:29 am
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)
tentus
Inner party member
Posts: 1060 Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:
Post
by tentus » Sun Jan 15, 2012 1:44 am
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.)
bartbes
Sex machine
Posts: 4946 Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:
Post
by bartbes » Sun Jan 15, 2012 10:58 am
You're probably better off using the origin arguments (ox and oy), because they correctly handle rotation as well.
Users browsing this forum: Ahrefs [Bot] , Bing [Bot] , Google [Bot] and 6 guests