4

我想使用 androidspritecocos2d中的移动制作动画,请帮助,这是我的代码:

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);
    }
}
4

4 回答 4

3

你可以这样做。这对我有用。恶魔1.png,devil2.png 像这样直到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));
于 2013-08-04T16:41:33.163 回答
3

你可以这样做:

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);
}
于 2013-03-14T10:45:34.367 回答
2

Vaishali 我正在使用这个:

 ArrayList<CCSpriteFrame> jumpForwardAnimation=jumpForwardDown();
                 CCAnimation crocodileEatFrogJumpsUpAnimation = CCAnimation.animation("throw", 0.14f, jumpForwardAnimation);

                 COUNTdOWNaCTION=CCAnimate.action(crocodileEatFrogJumpsUpAnimation, false);

    CCBezierConfig bezier = new CCBezierConfig();   

                 bezier.controlPoint_1=CGPoint.ccp(frog.getPosition().x+frog.getContentSize().width*0.5f,frog.getPosition().y+frog.getContentSize().height*0.6f);
                 bezier.controlPoint_2=CGPoint.ccp(frog.getPosition().x+frog.getContentSize().width*0.5f,frog.getPosition().y+frog.getContentSize().height);
                 bezier.endPosition=location;

                 CCBezierTo  action = CCBezierTo.action(0.5f, bezier);
                 CCFiniteTimeAction action2=CCSpawn.actions(COUNTdOWNaCTION,action );

                 CCFiniteTimeAction actionMoveDone = CCCallFunc.action(this, "frogMoveDone");
                 CCAction COUNTdOWNaCTION1=CCSequence.actions(action2, actionMoveDone);
                 frog.runAction(COUNTdOWNaCTION1);


public void frogMoveDone(){

        frog.setPosition(point);
        }

但是我的青蛙首先用贝泽路径动画到下一个位置,然后返回到之前的位置,然后它改变了它的位置。

你能告诉我在这里做错了什么吗?

于 2014-07-17T11:53:13.320 回答
2

我有一个使用以下代码在屏幕上显示动画的对象:

 CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFrames("ninjastar.plist");
 CCSpriteSheet projectileSheet = CCSpriteSheet.spriteSheet("ninjastar.png");
 addChild(projectileSheet);
 ArrayList<CCSpriteFrame> projectileSprites = new ArrayList<CCSpriteFrame>();

 for (int i = 1; i <= 4; i++) 
 {
     projectileSprites.add(CCSpriteFrameCache.spriteFrameByName("ninjastar" + i + ".png"));
 }



  CCAnimation projectileAnimation = CCAnimation.animation("throw", 0.1f, projectileSprites);
  CCSprite projectile = CCSprite.sprite(projectileSprites.get(0));
  CCAction projectileAction = CCRepeatForever.action(CCAnimate.action(projectileAnimation, false));
  projectile.setPosition(CGPoint.ccp(winSize.width + (projectile.getContentSize().width / 2.0f), actualY));
  actionMove = CCMoveTo.action(actualDuration, CGPoint.ccp(-      projectile.getContentSize().width / 2.0f + 320, actualY));
  projectileSheet.addChild(projectile);
  projectile.setTag(1);
  projectiles.add(projectile);

  CCCallFuncN actionMoveDone = CCCallFuncN.action(this, "spriteMoveFinished");
  CCSequence actions = CCSequence.actions(actionMove, actionMoveDone);
  projectile.runAction(actions);
  projectile.runAction(projectileAction);

我正在使用“spriteMoveFinished”来删除精灵,一旦它完成穿过屏幕:

  public void spriteMoveFinished(Object sender) 
  {
    CCSprite sprite = (CCSprite)sender;
    projectiles.remove(sprite);
    sprite.stopAllActions();
    sprite.removeFromParentAndCleanup(true);
  }
于 2014-07-17T09:22:02.937 回答