我是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];
}
任何人都可以指导我做错了什么.. 提前谢谢......
答案 0 :(得分: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];
答案 1 :(得分: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];