Question

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.

Was it helpful?

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.

OTHER TIPS

Consider that Flappy uses physics so you have to enable it before continue programming.

Second you need to enable touch inside didLoadFromCCB

self.userInteractionEnabled = TRUE;

Then you can use applyImpulse inside ccTouchesBegan

- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
[_hero.physicsBody applyImpulse:ccp(0, 400.f)];
}

I did flappy bird like game without using physics and just using cocos2d. CCbezier curve helped me achieve the same effect as in flappy bird. Its easy implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top