# Individual File Animation

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

## Recommended Posts

Not sure if this has been asked before, but I haven't been able to find any type of support of any kind in the past few days, so here I am.

What I would like to know, is how do you animate individual files in XNA? Currently I am using Cocos2D-XNA as a framework, and so far it's working pretty well, but it is not letting me animate individual files.

I have these files that I need to animate together (and no I will NOT use a SpriteSheet):

- Walk_0

- Walk_1

- Walk_2

- Walk_3

How do I make it so that the framework animate these files; without them having to be SpriteSheet (that I completely 100% refuse to use.)?

What I've tried so far:

- List<Texture2D> with each file frame in it. Outcome: Game freezes then unfreezes once the last animation is shown.

- using a foreach statement. Outcome: freezes the game.

- using do/while statement. Outcome: freezes the game.

- using for statement. Outcome: freezes the game.

##### Share on other sites

I'm not sure whether it works or not but as a suggestion, maybe you can set one texture2D as a reference and rewrite that every time you want to draw instead of changing the texture2D

Edited by Nathan Drake

##### Share on other sites

I'm not sure whether it works or not but as a suggestion, maybe you can set one texture2D as a reference and rewrite that every time you want to draw instead of changing the texture2D

To be honest, that's what I am currently trying to do. The thing is that this framework has a function texture.InitWithTexture(<texture here>); But the thing is that it only allows you to name one texture at a time. It doesn't allow you to do texture = (texture here); at all. So I get what you are trying to suggest, but from what I've tried so far, it isn't possible. I do appreciate the help/suggestion.

I also just tried using a label to see if I can "goback" and reInit the texture with a different one, but all it does is the same thing as the for/foreach/do/while statements...I'm slowly running out of options. Unless someone happens to know of a tutorial out there about animation with individual files using DirectX or XNA. It can be in C++. I do know the language and can read it, I just prefer C# over C++.

Edited by Elshlivious

##### Share on other sites

- using a foreach statement. Outcome: freezes the game.
- using do/while statement. Outcome: freezes the game.
- using for statement. Outcome: freezes the game.

If you stop the game loop to go into your own loop over each of the frames then it only makes sense that the game loop would…stop.
Obviously you have to show one frame of animation per frame of the game (or so). That means not using a foreach/for/do-while/etc.

(and no I will NOT use a SpriteSheet)

Sprite sheets have absolutely nothing to do with the current problem, but in any case yes you will. You will use a sprite sheet (texture atlas) once you start to care about performance and memory.

L. Spiro

Edited by L. Spiro

##### Share on other sites

- using a foreach statement. Outcome: freezes the game.
- using do/while statement. Outcome: freezes the game.
- using for statement. Outcome: freezes the game.

If you stop the game loop to go into your own loop over each of the frames then it only makes sense that the game loop would…stop.
Obviously you have to show one frame of animation per frame of the game (or so). That means not using a foreach/for/do-while/etc.

(and no I will NOT use a SpriteSheet)

Sprite sheets have absolutely nothing to do with the current problem, but in any case yes you will. You will use a sprite sheet (texture atlas) once you start to care about performance and memory.

L. Spiro

I' new to the Game Development field, so far I'm getting the hang of it except for animation I am having a hell of a lot of trouble with that.

As for the SpriteSheet, no, I will never use them. Because all my assets are in a compressed .data file or how they call it, a resource file. So no, I won't.

As for the Looping, someone told me a while ago that it's possible to animate using loops like for/foreach/etc. I guess they were wrong then. How should I go about it then?

Edited by Elshlivious

##### Share on other sites

a counter can be used to determine which frame to draw.

each time you render, you draw the appropriate frame, then increment the counter.

when you hit the last frame, stop the animation, or reset the counter to loop the animation.

loops can be used for stand alone or canned animations (IE cutscene animations) that pause the game and playback.

Edited by Norman Barrows

##### Share on other sites

a counter can be used to determine which frame to draw.

each time you render, you draw the appropriate frame, then increment the counter.

when you hit the last frame, stop the animation, or reset the counter to loop the animation.

loops can be used for stand alone or canned animations (IE cutscene animations) that pause the game and playback.

Took your advice, I guess I don't know much about counters since it didn't work that well, but I do greatly appreciate it since you comment led me into the solution (was up until 4 am trying to solve this glad I don't work till the afternoon.)

What I did:

for (int ii = 0; ii < frames.Count; ii++)
{
sprite[ii] = new CCSprite(textures[ii]);
sprite[ii].SetPosition(X * (float)2.91 / 2, Y * (float)2.86 / 2);
sprite[ii].SetTextureRect(new CCRect(0, 0, 800, 600)); // using this for now since 550/420 is too small for a windowed screen
}

anim.Loops = Convert.ToUInt32(10); // ignore this for now, this just means it'll loop ten times
anim.DelayPerUnit = 0.2f; // time delay per unit

CCAnimate ate = new CCAnimate(anim);
ate.Duration = 1.8f;
//ate

sprite[0].RunAction(new CCAnimate(anim));
//sprite[0] = new CCSp


and it actually works, thank for the help everyone. I usually need only picks and hits to solve these things, yes it takes me time, but that's the whole learning process, right?

Oh and yes I do know this current method isn't memory efficient (window runs at 77MBs and CPU spikes up for the beginning then goes down and stays low). But I'll find a better solution to that later on. Right now, I am just trying to make a bare bone skeleton of the game, then adding all the optimizations and all that good; like they say: use KISS.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631781
• Total Posts
3002319
×