Jump to content
  • Advertisement
Sign in to follow this  
somnambulism

Entity-component systems and animations

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm implementing a platformer in C++ using SFML and a port of Artemis. Right now, I'm currently working on a System that will animate my sprites. My understanding is that in ECS, components should only ever hold raw data (no resizable containers, objects, etc), but the best way I can conceptualize an AnimationSystem would be that every Entity that needs to be animated will have an Animation component, which would contain a list of Frames. Each frame would just hold data -- the x and y position within the texture, the width and height of the frame, and the relative duration of the animation.

If I implement that, the code will work just fine, but I feel like I'd have broken some golden NO-OBJECTS rule of entity design. I've implemented animations in other fashions but they don't have quite the capability --- I've not been able to put multiple animations on a single altas, or have animations where the frame width and height could change.

 

Has anybody had any experience with this? I'd like to get some guidance here :)

Edited by somnambulism

Share this post


Link to post
Share on other sites
Advertisement

Each frame would just hold data -- the x and y position within the texture, the width and height of the frame, and the relative duration of the animation.

 

I'd store just an id or reference string ("running", "standing", "crawling") in the animation component and have the animation system use this information to play the right animation. This system would eigther own a list of the actual animation data you described, or share it with the higher level structure that is responsible for creating it. Does that sound possible with your design?

Share this post


Link to post
Share on other sites

I use a Sprite abstraction that encapsulates a texture and contains a mapping of "frame indices" to rectangles within the texture. This is independent of my ECS.

 

My Aspect component (which is the visual representation of an entity) contains an id for the Sprite, and a frame index.

 

Then my FrameAnimation component just has a few simple properties (FrameRate, Direction, IsLoop, etc...). My FrameAnimationSystem uses that info to modify the frame index in the Aspect component.

Share this post


Link to post
Share on other sites

juliean - I believe I'll integrate the tags you've suggested into phil's solution in order to segregate different animations within a single atlas. thanks!
phil_t - I think that is the solution I am looking for. I've just started reading through your blog as well, it's a pretty good resource.

Share this post


Link to post
Share on other sites



If I implement that, the code will work just fine, but I feel like I'd have broken some golden NO-OBJECTS rule of entity design. I've implemented animations in other fashions but they don't have quite the capability --- I've not been able to put multiple animations on a single altas, or have animations where the frame width and height could change.

 

I don't understand why you can't have a resizable container and objects inside a component. 

Containers and objects are good way to encapsulate and store data.

Raw data doesn't mean that you only can have primitive types in a component. What you want to stay away from is having lots of functions in a component. That's system's job.

Use a vector to store each frame.

Edited by lride

Share this post


Link to post
Share on other sites

Use a vector to store each frame.

 

Generally agreed that there isn't anything against using a vector, and it is good use in some cases, I'd still say that some reference to the animation, in combination with what phil_t suggested, specially the paramters which I forget to mention. Its a matter of case, good thing you mentioned one should not stay away from vectors etc.. completely.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!