Page 1 of 1

How to load an animation (AnAL) on a body?

Posted: Thu Oct 08, 2015 1:47 am
by conradoc
Hello guys. It's my first topic. I'm new on Love world and I am getting started on implementing physics.

Before physics, I was making a 2d game using only basic functions. But now, I want to implement jump, gravity...

Without physics, I was using AnAL file to make the character to move. But now, I want to make it jump, so I need to implement physics. How can I draw this animations on a body?


thanks

Apologize for my English. I'm brazillian

Re: How to load an animation (AnAL) on a body?

Posted: Thu Oct 08, 2015 1:12 pm
by Karai17
You want to keep a handle of the physics body in your player table (or wherever) and poll the body's position every frame, then use that position to draw your animation.

Code: Select all

player.body = love.physics.newBody(world, x, y, type)

love.draw()
  local x, y = player.body:getPosition()
  lov.graphics.draw(animation, x, y)
end
I will note here that body:getWorldCenter might be better than body:getPosition, but I don't know. You will have to experiment.

I will also note that anim8 is a much better library than AnAL, you should consider using that instead.