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

1 回答 1

1

在此动画中首先完成,然后如果您触摸屏幕,那么您想要的活动就会发生.....如果您希望动画同时移动精灵,请在公共布尔 ccTouchesEnded(MotionEvent事件) { }

于 2013-02-27T13:30:12.340 回答