Reputation: 39
I am a total beginner to the cocos2d and i am stuccoed near a problem of making my sprite jump in vertical direction so please can anyone help me out of this situation... here is my code...
-(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];
}
can anyone guide me what i am doing wrong..
Thanks in advance...
Upvotes: 0
Views: 1625
Reputation: 1541
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];
Upvotes: 0
Reputation: 22042
You set 100 pixel jump in x-axis and 0 in y-axis. Try below code
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];
Upvotes: 4