2014-03-04 32 views
-2

所以我只是想做一個飛揚的鳥的副本。但是,我想知道如何實現鳥翼?我想用的方法你如何製作飛揚的鳥翼?

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

,但我注意到,如果您使用此方法,並按下屏幕上的鳥將持續震盪。當我點擊屏幕時,我只想讓鳥兒翻動,如果我在屏幕上按下它,它的行爲方式與點擊一次相同。

有沒有一個類的引用,利用這些行爲?

+0

https://github.com/kirualex/SprityBird – Marco

+0

其他的擋板代碼是什麼樣的? 'touchesBegan:'應該只爲屏幕上的每個水龍頭註冊一次。 – WolfLink

回答

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 
} 
0

I'm很沮喪,因爲我不能畫地像笨鳥先飛......我嘗試使用這種方法:

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

}

您可以下載的應用程序at here