2014-03-04 2 views
-2

그래서 나는 단지 반짝이는 새의 복제품을 만들려고 노력하고있었습니다. 그러나 나는 새 플랩을 달성하는 방법을 궁금해하고 있었습니까? 나는 방법어떻게 새빨간 플랩을 만들 수 있습니까?

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

를 사용하여 생각하지만 난 당신이이 방법을 사용하여 화면을 아래로 누르면, 새가 지속적으로 플랩 것으로 나타났습니다. 나는 화면을 누를 때 새가 흔들 리길 원하고, 화면을 누 르면 한 번 탭하는 것과 같은 방식으로 행동합니다.

이러한 종류의 동작을 사용하는 클래스 참조가 있습니까?

+0

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

+0

나머지 플랩 코드는 어떤 모양입니까? 'touchesBegan :'은 화면의 각 탭에 대해 한 번만 등록해야합니다. – WolfLink

답변

1

tap 이벤트를 얻으려면 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

미안 매우 좌절 플래 피 버드에 ... 나는이 방법을 사용하려고처럼 땅을 그릴 할수 없어 때문에 :

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