Animation creation [2d]

I am trying to create an animation for my game but don’t understand how to transition the sprites from my character sheet, could anyone possibly help?

SpriteBatch takes a source rectangle that specifies which region of the texture should be drawn. You want to change this rectangle based on the frame your animation is in. Let me know if that’s not enough to help you on your way. I’m on mobile, so I can’t make a decent drawing to visualize it :stuck_out_tongue:

1 Like

To create the animation I use two Rectangles’, one will be used to determine the area of the spritesheet that will be used, and the second will take that area and draw it to the screen. spriteBatch.Draw(texture, drawRec, frameRec, Color.White);

To work out the position of the first Rectangle over the spritesheet I have a variable to store the frame number starting at 0 counting up to 11(for this sheet), this will be used to work out the X position “Current Position * Frame Width = X position”.

frameRec.
Walk right Frame 0 x 43 = 0 Rectangle position: X = 0, Y = 0

Walk right Frame 1 x 43 = 43 Rectangle position: X = 43 , Y = 0

Walk left Frame 3 x 43 = 129 Rectangle position: X = 129 , Y = 64

3 Likes