2012-02-06 173 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){ }