0

我是 cocos2d 的初学者,我遇到了让我的精灵在垂直方向跳跃的问题,所以请任何人都可以帮助我摆脱这种情况......这是我的代码......

-(id) init
{
    if( (self=[super init])) {
        // enable touches
        self.isTouchEnabled = YES;

        // enable accelerometer
        self.isAccelerometerEnabled = YES;

        ManStanding = [CCSprite spriteWithFile:@"ManStanding.png"];
        [ManStanding setPosition:ccp(40,0)];
        [self addChild:ManStanding];
    }
    return self;
}

-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{

    id jump = [CCJumpBy actionWithDuration:1 position:ccp(100, 0)
                                   height:50 jumps:1];
    [ManStanding runAction:jump];
}

谁能指导我我做错了什么..
提前谢谢...

4

2 回答 2

4

您在 x 轴设置 100 像素跳跃,在 y 轴设置 0。试试下面的代码

    id jump_Up = [CCJumpBy actionWithDuration:1.0f position:ccp(0, 200)
                                    height:50 jumps:1];
    id jump_Down = [CCJumpBy actionWithDuration:0.7f position:ccp(0,-200)
                                    height:50 jumps:1];

    id seq = [CCSequence actions:jump_Up,jump_Down, nil];

    [sprite runAction:seq];
于 2013-05-27T08:55:10.140 回答
0
id uppar = [CCJumpBy actionWithDuration:0.9f position:ccp(100,0) height:0 jumps:1];
id down = [CCJumpBy actionWithDuration:0.9f position:ccp(-100,0) height:0 jumps:1];
id seq = [CCSequence actions:uppar,down, nil];
[user1 runAction:seq];
于 2016-05-07T06:04:07.610 回答