-2

所以我只是想制作一个飞扬的鸟的复制品。但是,我想知道如何实现鸟翼?我想到了使用方法

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

但我注意到,如果你使用这种方法并按下屏幕,小鸟会不停地拍打。我只是想让小鸟在我点击屏幕时拍打,如果我按下屏幕,它的行为与点击一次相同。

有没有利用这些动作的类参考?

4

2 回答 2

1

要获取点击事件,您可以使用 Apple 提供的 UITapGestureRecognizer。只需启动它,根据您的要求设置参数并将其添加到您要记录点击的视图中。

    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

并定义您在初始化中提到的选择器。

- (void)handleTap:(UITapGestureRecognizer *)recognizer{
         // Handle the tapping here
}
于 2014-03-04T06:51:06.937 回答
0

我很沮丧,因为我不能像在 Flappy Bird 中那样绘制地面......我尝试使用这种方法:

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);
}

}

您可以在这里下载应用程序

于 2014-03-06T08:41:36.297 回答