Search code examples
objective-ccocos2d-iphoneflappy-bird-clonecocos2d-iphone-2.x

How to make controls similar to flappy bird in cocos2d


I am making a game in cocos 2d v2 and was wondering how to make my controls similar to flappy bird so when you tap it slowly moves up and when you let go it drops.

I am trying to use ccTouchesBegan and ccTouchesEnded but this isn't working quite right. Here is what I have so far:

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    Y += 3; 
   [self schedule:@selector(movePlayer:)interval:1.0f/60.0f];
}

-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    Y -= 2; 
   [self schedule:@selector(movePlayer:)interval:1.0f/60.0f];
}

-(void)movePlayer:(ccTime)dt{ 
    player.position = ccp(player.position.x, player.position.y + Y);
}

The Y variable is simply just an int initialized to 0 set up in my header file.


Solution

  • Try this tutorial:

    https://www.makegameswith.us/gamernews/369/build-your-own-flappy-bird-with-spritebuilder-and

    I don't know if you have access to SpriteBuilder used in this tutorial, but it helped me to create a very authentic looking Flappy Bird clone.