I want to animate a moving sprite
in cocos2d using android, help please
here is my code:
public void setMoveAnimation(CCSprite target) {
//CCSprite target = CCSprite.sprite("Target.png");
CCAnimation OpenAnim = CCAnimation.animation("", 0.1f);
for (int i = 1; i <= 2; i++) {
OpenAnim.addFrame(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("target.0" + i + ".png"));
CCAction MoveAction = CCAnimate.action(1, OpenAnim, false);
target.runAction(MoveAction);
}
}
you can do like this. this is working for me. devil1.png,devil2.png like this upto devil4.png
CCAnimation animation = CCAnimation.animation("dance", 0.2f);
for (int i = 1; i < 5; i++) {
animation.addFrame(CCFormatter.format(devil%d.png, i));
}
CCIntervalAction action = CCAnimate.action(animation);
target.runAction(CCRepeat.action(action, 9));
You can do this:
public void openScrPpr(float duration, CCSprite player) {
CCAnimation scrPprAnim = CCAnimation.animation("", 2 / 20f);
CGSize size = CCDirector.sharedDirector().displaySize();
CCMoveTo moveTo = CCMoveTo.action(1,
CGPoint.ccp(size.getWidth(), (size.getHeight() - 40)));
for (int i = 1; i <= 7; i++) {
scrPprAnim.addFrame(CCSpriteFrameCache.sharedSpriteFrameCache()
.spriteFrameByName(i + ".png"));
if (i == 7) {
for (int j = 7; j >= 1; j--) {
scrPprAnim.addFrame(CCSpriteFrameCache
.sharedSpriteFrameCache().spriteFrameByName(j + ".png"));
}
}
}
CCIntervalAction scrPprAction = CCAnimate.action(duration, scrPprAnim, false);
CCRepeatForever forever = CCRepeatForever.action(scrPprAction);
CCRepeatForever forever2 = CCRepeatForever.action(moveTo);
player.runAction(forever);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With