2013-05-27 84 views
0

我是cocos2d的總初學者,我在灰燼附近讓我的精靈在垂直方向跳躍的問題附近,所以請任何人都可以幫助我擺脫這種情況... 這裏是我的代碼...在cocos上做精靈跳2d

-(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

您設置y軸在x軸100像素跳躍和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]; 
+0

正如我調試我才知道該事件 - (BOOL)ccTouchBegan:(UITouch *)觸摸withEvent:方法(的UIEvent *)事件不會解僱我怎樣才能解決這個問題。 –

+0

嘗試 - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; – Guru

+1

如果你的cocos2d版本2.0然後使用self.touchEnabled = YES;而不是self.isTouchEnabled – Guru

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];