Hey I’m currently making a 2D fighter a lot like the good old Mortal Kombats using XNA 4.0. Anyway, I’m currently trying to program a punch animation.
The player is in the Idle state and on pressing Left Control, the player should punch.
Now assume the player is facing the left of the screen. All my sprites are drawn facing the right. So when the player punches, the sprite is flipped and drawn.
Problem is, the animation makes it look like the player teleports to the right abruptly because it is aligning the left most part of the flipped punch frame with the left most part of his idle frame (that’s what I think at least). I cannot seem to think of a way to fix this.
My code is quite big right now. If someone could identify a possible section of the problem, I’d be glad to post that code.
Okay so I fixed that problem. Indeed the problem was the sprite sheet. The guy who designed it, did not center each image in each frame.
So then, he centered all the images, but the frames were of varying sizes. But that problem persisted.
After some debugging, I figured out what was happening. In the Idle frames, there was a 2-pixel space on either side of the character in those frames. In the Punch frames, there was a 23-pixel space on either side of the character in those frames.
My
Draw()function was drawing each frame based on a 2D position Vector. This position Vector, specifies the top-left corner of each frame.Now since the Idle frames and the Punch frames have differing pixel widths to the left of the characters in each frame, it looked like the character “teleported” when the player presses Punch.
Now my solution for this problem – make all the frame sizes the same! This solved my “teleportation” issue. I could’nt figure out any alternative solutions to this problem though.
Now there’s one thing I don’t understand. There are so many games where sprite sheets are made up of different frame sizes. How do they use them without this teleportation issue?!