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