After years of prototyping and messing around I’m finally trying to finish a game and man, this ECS thing is a struggle.
So in the past I’ve always written my little games using the, now-out-of-fashion, OOP way of base class with update, draw, etc. I had a lot of success. So I thought since I was going to try this “for real” I would see what the pros are doing and I stumbled across ECS and the myriad of content out there surrounding it.
I didn’t start out with any frameworks as I’m happy to write it myself. At first everything worked great-I had a lean Entity class, Postion component, Renderable component, a RenderingSystem and I was drawing little static sprites all over the screen. Then I tried to adapt my AnimatedSprite class and it all fell apart.
So I then I thought, hey, other people have solved this, let me look at some ECS frameworks. What I found were a lot of highly optimized skeletons with no reference implementations or reference implementations that seemed nothing like what I was told ECS was. I’m truly not being critical of the awesome open-source frameworks out there, but I haven’t found one that implements the concept of an AnimatedSprite using “pure” ECS, meaning an Entity with little more than an ID, Components that only store data and Systems that do all the logic.
In my prototype I have everything all wired up with a nice state machine that can trigger animations and transitional animations and can loop, ping-pong, etc. I’m just having a real helluva time adapting that to ECS without writing really sloppy code.
OK, so for some focused questions:
-
Man, I’d love to see your ECS state machine and animation system. Can I?
-
In a property/field-only Component how do you track current delta time other than constantly decorating your Compontent with it? Meaning, I need to know when to switch animation frames based on some kind of speed variable compared to accumulated time. Is it appropriate to store that at the Component level? I feel like my Components are just getting super busy.
-
How granular should a Component be? Maybe that’s my problem? At a certain point ECS seems pointless if your Components are just versions of OOP-style entities.
Based what I’ve seen I feel like everyone ends up with some kind of hybrid approach.
Thank you for your patience.
EDIT: yes, I’ve looked through this: GitHub - SanderMertens/ecs-faq: Frequently asked questions about Entity Component Systems