2012-02-06 170 views
0

如何在跳躍時動畫精靈? 即移動眼睛或動畫使用CCAnimate跳躍時動畫精靈

CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFrames("AnimBear.plist"); 
    this._bear = CCSprite.sprite("bear1.png", true); 


    spritesheet1 = CCSpriteSheet.spriteSheet("AnimBear.png"); 

    spritesheet1.addChild(_bear, 1); 

    addChild(spritesheet1, 1); 

    ArrayList<CCSpriteFrame> animFrames = new ArrayList<CCSpriteFrame>(); 
    CCSpriteFrameCache.sharedSpriteFrameCache(); 
    for (int i = 1; i <= 8; i++) { 
     CCSpriteFrame frame = CCSpriteFrameCache 
       .spriteFrameByName(
         "bear" + i + ".png"); 
     animFrames.add(frame); 
    } 
    CCAnimation anim = CCAnimation.animation("AnimBear", .175f, 
      animFrames); 

    _bear.setPosition(CGPoint.make(_bear.getContentSize().width, 50)); 



    CCIntervalAction action=CCAnimate.action(0.1f, anim, false); 
    this.walkAction = CCRepeatForever.action(action); 

    _bear.runAction(walkAction); 

精靈和觸摸

public boolean ccTouchesEnded(MotionEvent event) { 


     CGPoint touchLocation = CCDirector.sharedDirector().convertToGL(
       CGPoint.make(event.getX(), event.getY())); 

     float bearVelocity = 480.0f/3.0f; 
     CGPoint moveDifference = CGPoint.ccpSub(touchLocation, _bear.getPosition()); 
     float distanceToMove = CGPoint.ccpLength(moveDifference); 
     float moveDuration = distanceToMove/bearVelocity; 

     if (moveDifference.x < 0) { 
      _bear.flipX_= false; 
     } else { 
      _bear.flipX_ = true; 
     }  

     _bear.stopAction(moveAction); 

     if (!_moving) { 
      _bear.runAction(walkAction); 
     } 
     CCMoveTo actionMove=CCMoveTo.action(moveDuration, touchLocation); 
     CCCallFuncN actionMoveDone1 = CCCallFuncN.action(this, "bearMoveEnded"); 
     CCSequence actions = CCSequence.actions(actionMove, actionMoveDone1); 
     _bear.stopAllActions(); 
     this.moveAction = actions; 

     _bear.runAction(moveAction); 

     _moving = true; 

     return CCTouchDispatcher.kEventHandled; 
    } 

回答

1

朝着這個動畫完成第一,在此之後,如果你觸摸屏幕上隨後將活性你想要它會發生..... 如果要動畫n同時移動精靈,請完成 中的所有代碼public boolean ccTouchesEnded(MotionEvent event){ }