1

I'm working on Cocos2D, and I need to make the sprite jump from position(x, y) to position(width-x, y) in a parabolic way. It's my first time working in game development.

How can I make the animation of jumping from one side to the other side?

My current piece of code while screen is tapped

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGSize screenSize = [[CCDirector sharedDirector] winSize];

    if(!self.anim.flipY){
        self.anim.position = ccp(screenSize.width - self.anim.position.x, self.anim.position.y);
        self.anim.flipY = true;
    }
    else{
        self.anim.position = ccp(screenSize.width - self.anim.position.x, self.anim.position.y);
        self.anim.flipY = false;
    }

}

I read on a forum, that it requires to use gravity and velocity? Any hint? I barely have an idea!

4

1 回答 1

1

我不确定这是否是您需要的,但您可以使用动作进行精灵跳跃。

// Create a CCJumpTo action.
CCJumpTo *jumpAction = [CCJumpTo actionWithDuration:2.0 position:ccp(100,100) height:50 jumps:1];
// Tell your sprite to run our action.
[mySprite runAction:jumpAction];

还有CCJumpBy

它们具有抛物线风格。玩弄这个height论点。

于 2013-06-15T00:59:28.553 回答