Jump to content

  • Log In with Google      Sign In   
  • Create Account

Individual File Animation


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1 Elshlivious   Members   -  Reputation: 107

Like
-1Likes
Like

Posted 09 February 2016 - 12:25 AM

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.



#2 Nathan Drake   Members   -  Reputation: 657

Like
0Likes
Like

Posted 09 February 2016 - 12:42 AM

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, 09 February 2016 - 12:44 AM.


#3 Elshlivious   Members   -  Reputation: 107

Like
0Likes
Like

Posted 09 February 2016 - 01:42 AM

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, 09 February 2016 - 01:47 AM.


#4 L. Spiro   Crossbones+   -  Reputation: 23975

Like
0Likes
Like

Posted 09 February 2016 - 02:00 AM

- 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, 09 February 2016 - 02:01 AM.


#5 Elshlivious   Members   -  Reputation: 107

Like
-2Likes
Like

Posted 09 February 2016 - 02:10 AM

 

- 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, 09 February 2016 - 02:10 AM.


#6 Norman Barrows   Crossbones+   -  Reputation: 5254

Like
0Likes
Like

Posted 09 February 2016 - 07:44 AM

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, 09 February 2016 - 07:45 AM.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

 

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

 

 


#7 Elshlivious   Members   -  Reputation: 107

Like
0Likes
Like

Posted 09 February 2016 - 01:31 PM

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.AddSprite(sprite[ii]);
                }

                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));
                AddChild(sprite[0]);
                //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.






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS