Public Group

# Need help understanding this way of animating sprites.

This topic is 2445 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am using the book "Learning XNA 4.0"

http://codepaste.net/f6w368 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 on other sites
Its kind of like arrays

array[x]

=arraystart + elementsize*x

i believe

##### 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).

Example:
currentFrame = 0

first sprite starts at (0,0) => (currentFrame*framesize.X, currentFrame*framesize.Y)
currentFrame++
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 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 >_>

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
A4L
13
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013658
×