所以我只是想制作一只易飞鸟的复制品。但是,我想知道如何实现鸟皮瓣?我想过使用方法
- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
但是我注意到如果你使用这种方法并按下屏幕,鸟会不断拍打。我只是想在点击屏幕时让鸟儿翻动,如果我按下屏幕,它的行为方式与点击一次相同。
是否有使用这类行为的类引用?
答案 0 :(得分: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
}
答案 1 :(得分: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);
}
}
您可以在here
下载应用