سؤال

Well, actually I am asking a question about a CCAnimation example in book "Learn cocos2d". In the example (ch6), I don't see any code to define the position to CCAnimation, I only see the CCSprite-derived class, called "Ship", was given a position.

Why? The CCAnimation knows where to animate?

Thanks

هل كانت مفيدة؟

المحلول

CCAnimation has no position. An animation just changes the sprite frames (textures) of a sprite (the Ship). Therefore the ship's position determines where the animation is played.

نصائح أخرى

CCAnimation deals on a sprite, so you have to provide position for the sprite. CCAnimation is not a subclass of CCNode so you can't set position for it.

The purpose of CCAnimation is to animate frames of animation not position of sprites. To move a sprite into some position you would have to use CCActionMoveBy (Cocos2d v3) or CCActionMoveTo.

Update

Consider the case where you have a character with a dance animation which is represented by several frames. The character would be a CCSprite, the dance animation would be the CCAnimation containing all the frames (plus other things like the speed of playback). You would position your character sprite using either the CCSprite's position property or by using actions like CCActionMoveBy/CCActionMoveTo, then you would play the dance animation using CCAnimate.

If later you decide to add a flip animation, you would create another CCAnimation with the corresponding frames then position the character and play the flip animation.

It wouldn't make sense for CCAnimation to hold any position information because both animated and non animated sprites need to be positioned.

Hope this clarifies things a bit.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top