2

I am working on my first sizable C++ program; a 2-D mario platformer remake.

I currently have an animation class that encapsulates all of the functionality of my animations for all the bad-guys called Animation. Then, I wanted to create the animation class for mario, let's call it MarioAnimation. Mario has an ability, can jump, and is animated at a different rate than my bad-guys, so, I felt it unnecessary to cover all animations with just the Animation class and felt good about my decision because objects would carry unnecessary functions along with them. Thus, I created another Animation class, AbilityAnimation that had functions specific to how a Fireball would be animated. Now, I just finished the basics for my ItemAnimation class. The next step is creating BlockAnimations for the animations of floating blocks and platforms. It's beginning to seem like half of each class is similar but not the same and each has 1-3 entirely unique functions. It's making me feel on-the-fence about my design decision.

Should I go back and try to generalize my Animation function, or is it better to keep my Animation classes specific so as to not carry extra baggage on each object?

Thanks in advance for any advice you may have.

1

From the sounds of things, my hunch is to say that yes you should generalise your animation class (full disclosure, I don't make games so do take it with a pinch of salt!). Your opening line is the clue: 'I currently have an animation class that encapsulates all of the functionality of my animations for all the...'

This sounds like a mistake right off the bat, to me your animation class deals with updating your sprites for all of your entities (entities being mario, enemies, etc). Every entity needs to call an animation update at some point, if mario jumps for instance, he calls his version of animation.update, which in turn checks his state (which is now jumping) and updates his sprite to the appropriate image. When an enemy moves, its state is changes to 'moving' and calls its version of animation.update, which in turn updates its animation accordingly. Does that make sense?

There is always the risk of over abstraction, but I think here you should focus on greater separation of concerns.

  • Definitely makes sense. I think you are right. The more I think about it, the more it seems that trying to avoid tacking on extra functions to objects that don't need them is negligible compared to the extra classes just making things harder to follow and unnecessarily complicated. I appreciate your help! – Brandon Chatham Oct 8 '16 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.