Jump to content

  • Log In with Google      Sign In   
  • Create Account


How to organize animation functionality


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 warnexus   Prime Members   -  Reputation: 1380

Like
0Likes
Like

Posted 06 November 2013 - 09:45 AM

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.

 

 



Sponsor:

#2 Paragon123   Members   -  Reputation: 396

Like
0Likes
Like

Posted 07 November 2013 - 04:04 PM

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.



#3 warnexus   Prime Members   -  Reputation: 1380

Like
0Likes
Like

Posted 07 November 2013 - 06:51 PM

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

#4 wintertime   Members   -  Reputation: 1601

Like
0Likes
Like

Posted 08 November 2013 - 05:18 AM

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



#5 warnexus   Prime Members   -  Reputation: 1380

Like
0Likes
Like

Posted 08 November 2013 - 09:35 AM

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, 08 November 2013 - 09:35 AM.


#6 Paradigm Shifter   Crossbones+   -  Reputation: 5126

Like
0Likes
Like

Posted 08 November 2013 - 09:46 AM

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, 08 November 2013 - 09:47 AM.

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

#7 Álvaro   Crossbones+   -  Reputation: 11865

Like
0Likes
Like

Posted 08 November 2013 - 10:01 AM


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

 

Funniest comment I've read all year. :)



#8 Paradigm Shifter   Crossbones+   -  Reputation: 5126

Like
0Likes
Like

Posted 08 November 2013 - 10:07 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS