Jump to content
  • Advertisement
Sign in to follow this  
Nicholas Kong

How to organize animation functionality

This topic is 2077 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

Currently, I have all my animation functionality all put into a class called Spiderman.

 

For example, every functionality that makes allow Spiderman to move left, right, become idle or use his shield is inside a class

called Spiderman.. So all the reading and drawing images and the logic that dictates which state is inside and what interval and frame of animation is inside this Spiderman class.

 

I am starting to get a little worried because the class is at 800 code long and I am not sure how well I can keep track of where things is if I wind up giving Spiderman more states. More states more lines of code.

 

Is there a way to organize like spread out the animation functionality? I am coding in Java.

 

 

Share this post


Link to post
Share on other sites
Advertisement

It's hard to help because we don't know how you are describing the data now, how many of the 800 lines of code are specifically for describing animation? 

How many lines are required for a single animation state... a single frame of the animation, is it 2D or 3D animation? 

 

You might find it less cumbersome to put all the required information into a file that the class reads to populate animation information.

Share this post


Link to post
Share on other sites

It's hard to help because we don't know how you are describing the data now, how many of the 800 lines of code are specifically for describing animation?
How many lines are required for a single animation state... a single frame of the animation, is it 2D or 3D animation?

You might find it less cumbersome to put all the required information into a file that the class reads to populate animation information.

Sorry if I did not present my issue clearer.

It is a 2D game in Java.

800 lines of code in Spiderman class that performs the following:
1) loading art assets for spiderman's movement, attacks
2) anything that makes the animation logic work (ie: array that contains a sequence of fixed intervals for each frame, animation counter)
3) movement logic( jumping logic, walking logic)
4) state management (death, walk, shield, jump)
5) collision against monsters and a solid brick object
6) playing sound when spiderman dies

12 lines for loading art assets of each animation state.
10 lines of code for each animation state logic. All it takes is a for loop.
roughly 15 lines for playing each sound

Share this post


Link to post
Share on other sites

You present a huge list as if it was normal, but a class should ideally have a single responsibility and not 6+. Sticking everything into one god class will bite you.

http://stackoverflow.com/questions/14870377/how-do-you-refactor-a-god-class

Thanks! Time to fix this god class. Sorry, I am still learning good design.

 

At first glance, when I write it seems to be perfectly fine. Thanks for the point out.

Edited by warnexus

Share this post


Link to post
Share on other sites

Each class should have a single responsibility. I mainly use C++, so

 

class Spiderman

{

public:

    // Spiderman::Spiderman, does whatever a spider can

    Spiderman();

    void SpinAWeb(Size any);

    void Catch(Container<Thief>&); // catches Thieves like flies. May throw

   

    // attributes

    bool IsStrong() { return true; }

    bool HasRadioactiveBlood() { return true; }

    bool CanSwingFromThread() { return true; }

   

    Action GetReward();

 

    friend class Neighborhood;

};

Edited by Paradigm Shifter

Share this post


Link to post
Share on other sites


// Spiderman::Spiderman, does whatever a spider can

 

Funniest comment I've read all year. :)

Share this post


Link to post
Share on other sites

I was inspired

 

 

Spider-Man, Spider-Man,
Does whatever a spider can
Spins a web, any size,
Catches thieves just like flies
Look Out!
Here comes the Spider-Man.

Is he strong?
Listen bud,
He's got radioactive blood.
Can he swing from a thread
Take a look overhead
Hey, there
There goes the Spider-Man.

In the chill of night
At the scene of a crime
Like a streak of light
He arrives just in time.

Spider-Man, Spider-Man
Friendly neighborhood Spider-Man
Wealth and fame
He's ignored
Action is his reward
Look Out!
Here comes the Spider-Man.

Spider-Man, Spider-Man
Friendly neighborhood Spider-Man
Wealth and fame
He's ignored
Action is his reward
Look Out!
Here comes the Spider-Man.

In the chill of night
At the scene of a crime
Like a streak of light
He arrives just in time.

Spider-Man, Spider-Man,
Does whatever a spider can
Spins a web, any size,
Catches thieves just like flies
Look Out!
Here comes the Spider-Man.

Spider-Man, Spider-Man
Friendly neighborhood Spider-Man
Wealth and fame
He's ignored
Action is his reward
Look Out!
Here comes the Spider-Man.

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!