How to organize animation functionality

Started by
6 comments, last by Paradigm Shifter 10 years, 5 months ago

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.

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.

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

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

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.

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;

};

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley


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

Funniest comment I've read all year. :)

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.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

This topic is closed to new replies.

Advertisement