0

助けが必要。私は何日もこの問題で立ち往生しています...私はタッチ・トゥ・キルの鳥撃ちゲームをしています。鳥が触れると、血しぶきをアニメーション化する一連の画像で死にます..そして鳥は静的で、時々飛ぶ..次のコードで静的部分を簡単に行うことができます:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
   if ([touches count]==1)
   {    
    location = [mytouch locationInView:self];
    UIView *killView = [self hitTest:location withEvent:nil];

    if ([killView isKindOfClass:[UIImageView class]]) {
        birdKilled = YES;
        [self addSubview:[self bloodSplash:killView]];}}}



-(UIImageView *)bloodSplash:(UIView*)killedView {
    UIImageView *blood = [[UIImageView alloc] 
          initWithFrame:CGRectMake(killedView.center.x-100.0/2.0,    killedView.center.y-100.0/2.0, 100, 100)];
    [killedView setHidden:YES];
    blood.image = [bloodExplodes objectAtIndex:2];
    [blood setAnimationImages:bloodExplodes];
    [blood setAnimationDuration:0.4];
    [blood setAnimationRepeatCount:1];
    [blood startAnimating];            
    [self performSelector:@selector(cleanBlood:) withObject:blood afterDelay:.8];
    return [blood autorelease];}

でも飛んでる部分はすごく行き詰まってます!飛んでいる鳥をアニメーション化するときにそれを学ぶので。hitTest でそのプレゼンテーション層を検出する必要があります。「UIViewAnimationOptionAllowUserInteraction」をオンにして正常に実行できます..しかし、問題は、UIImageViewをCALayerに返すため、bloodSplash関数をタッチポイントに追加する方法がわからないことです..これは私の試行です...

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

    if ([flyingBird.layer.presentationLayer hitTest:location]) {
     CALayer* touchedLayer = 
       [flyingBird.layer.presentationLayer hitTest:location];
    //No Idea what to do next..
  }}

Coz私はレイヤーについて本当によく知りません..アドバイスがあればThx。

4

1 に答える 1

0

飛んでいる鳥のビューに画像ビューを追加するには、正しいビューを見つける必要があります。UIViewはCALayerによってサポートされており、レイヤーにはそのデリゲートとしてUIViewがあります。アニメーション化するときは、プレゼンテーション層でhitTestを実行してから、モデル層に戻る必要があります。これは、モデル層に関連しているためです。そこから、レイヤーのデリゲートにクエリを実行することで、対応するUIViewを見つけることができます。したがって、次のようになります。

CALayer *hitLayer = [[flyingBird.layer.presentationLayer hitTest:location] modelLayer];
UIView *hitView = [hitLayer delegate];

これは、アニメーションUIImageViewを追加できるビューである必要があります。

于 2012-09-16T10:08:08.663 に答える