On Sat, Feb 22, 2014 at 4:26 AM, Mikko Finell <[email protected]>wrote:
> Hi, I used to post here as Paul Pittlerson, but as usual I change my name
> now and then. Haven't posted much lately
> as I learned how to figure out some things on my own, and I'm sure Claudio
> will be thankful for that fact :D
>
>
Hi, undisclosed entity :D
> Anyway I have been working on a project and will soon come to the point
> where I need to find a good way to add unit
> animations in a generic and scalable manner.
>
> Every unit will need a minimum of idle, walking (up, down, left, right),
> fighting (in the directions) and death. So it's a
> handful in a single unit. Now, I may be capable to figure out some way to
> execute this, but I was hoping to make use
> of some pre existing wisdom and ask for advice.
>
> Basically: What is a good way to keep track of several animations in a
> layer, and be able to switch between them in a
> effective and straight forward manner?
>
>
A common way is
- have an Actor class that cares for all the behavior of entities
(player, green_monster, etc)
- have some methods in that class with the public API for animations
(they can be coded as a mixin class)
- load and initialize all animation data for the actor
- play_animation(name, [extra params]) -> switches to sequence name,
internally stores the start time for current animation sequence
- _update_animation(dt) -> advances animation time, calc if a new
image is needed, if so update the actor image
- Have an adequate data structure to hold the animation description,
usually a dict with sequence name as key ( 'idle', 'walk_left', etc ) and a
list of tuples with ( frame_duration, frame_info ).
frame_info at least needs to specify which image is needed, but may
have extra info like dimensions of collision rect.
A minimal data example may look as
anim_data = {
'idle': [(0, 'player_idle'), ],
'walk_left': [(0.1, 'walk_left_1'), (0.1, 'walk_left_2'), ...],
...
}
> Thanks. Link to my repo if anyone is interested (warning for spaghetti
> code :P!):
> https://github.com/MikkoFinell/bullet
>
>
I will give a try
--
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/groups/opt_out.