-2

So I was just trying to make a replica of flappy bird. But, I was wondering how to achieve a bird flap? I thought of using the method

- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event

but I noticed that if you use this method and press down on the screen, the bird will flap continuously. I just want the bird to flap when I tap the screen, and if I press down on the screen it will behave the same way as tapping once.

Is there a class reference that utilizes these sort of action?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
chanpkr
  • 895
  • 2
  • 10
  • 21

2 Answers2

1

For getting the tap event, you can use the UITapGestureRecognizer provided by Apple. Simply initiate it, set the parameters according to your requirements and add it to the view you want to record the tap.

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    tap.numberOfTapsRequired = 1;
    tap.numberOfTouchesRequired = 1;
    [demoView addGestureRecognizer:tap]; // The gesture recognizer is being added to demoView
    [tap release]; // In case of not using ARC

And the define the selector which you mentioned in the initialization.

- (void)handleTap:(UITapGestureRecognizer *)recognizer{
         // Handle the tapping here
}
Zen
  • 3,047
  • 1
  • 20
  • 18
0

I´m very frustrated because I can´t draw the Ground like in Flappy Bird... I try to use this method:

private void drawGround(){  
for(Rectangle mRectangleGroundHelper : mArrayGround){
    if(spawnGround & mRectangleGroundHelper.x<0){ // spawn Ground if the actual ground.x + ground.width() is smaller then the display width.
        mArrayGround.add(mRectangleGroundHelper);
        spawnGround = false;
    }
}
for(Rectangle mRectangleGroundHelper : mArrayGround){
    if(mRectangleGroundHelper.x < -mTextureGround.getWidth()){ // set boolean to true, if the actual ground.x completely hide from display, so a new ground can be spawn
        spawnGround = true;
    }
}

for(Rectangle mRectangleGroundHelper : mArrayGround){ // move the ground in negative x position and draw him...
    mRectangleGroundHelper.x-=2;
    mStage.getSpriteBatch().draw(mTextureGround, mRectangleGroundHelper.x, mRectangleGroundHelper.y);
}

}

You can download app at here