Sign in to follow this  

Need help understanding this way of animating sprites.

Recommended Posts

I am using the book "Learning XNA 4.0" is the code

What I am not getting is, the currentFrame.X * frameSize.X. Seeing as how anything mutlipled by 0 = 0. Only other way I think how this works is, when currentFrame++ happens, it becomes 1*75, etc. But this is still a bit fuzzy to me, can someone help me understand this?

The sheetsize is 6 frames by 8 frames. And the sprite size is 75x75. And I am not exactly experienced with Points, so thats what had me somewhat more confused.

Share this post

Link to post
Share on other sites
The first sprite would start at (0,0) => (0*framesize.X, 0*framesize.Y) while the 2nd would be start at (1*framesize.X, 0*framesize.Y), the next one (2*framesizeX,....).
Remember, textures start on the top left, the (0,0) point and the y axis goes down(screenSizeX/ScreenSizeY) would be the Bot right on your screen.

So your animationsprite starts at point(currentFrameX*framesize.X, currentFrameY*framesize.Y) and is framesizeX and framesizeY wide.(so the end point X would be the starting point for the next frame).

currentFrame = 0

first sprite starts at (0,0) => (currentFrame*framesize.X, currentFrame*framesize.Y)
2nd sprite starts at (1,0) = (currentFrame*framesize.X, currentFrame*framesize.Y)
When X is >= the wide of your sheet, you increase y by 1 and x starts again at 0.
You do the same thing as above until you finish the next row.

Share this post

Link to post
Share on other sites
I believe I understand now, it was the currentFrame * frameSize stuff irritating me, but because it's a Point and not an int it wouldn't be the same as 0 * 75 = 0. That makes sense, I guess. Thanks for the help, no matter how stupid I look >_>

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this