Tuesday, August 7, 2012

Cocos2d This is How I make the player move back and forth


this is my function

-(void)playergo:(int) x: (int) y
{
    id action1 = [CCMoveTo actionWithDuration: x position:ccp(0, y)];
    
    id flip=[CCFlipX actionWithFlipX:YES];
    
    id action2 = [CCMoveTo actionWithDuration: x position:ccp(480, y)];
    
    id flipback=[CCFlipX actionWithFlipX:NO];
    
    

    
    
    
    id actionRepeatForever = [CCRepeatForever actionWithAction:
                  [CCSequence actions:action1,flip,action2,flipback, nil]
                  ];
    
   [self runAction: actionRepeatForever];
    
    //[self runAction: [CCSequence actions:action1,action2, nil]];

   
}

this is how i call the function
 [myplayer[0] playergo:5 :200];
 [myplayer[1] playergo:7 :220];
 [myplayer[2] playergo:9 :240];
 [myplayer[3] playergo:11 :260];
 [myplayer[4] playergo:13 :280];



below is the video, please enjoy, 

No comments:

Post a Comment