【发布时间】:2014-09-11 03:16:10
【问题描述】:
我一直在尝试实现一种方法,用户可以按下播放按钮,然后将纹理更改为按下的图像。然后,如果用户决定不继续他们的操作。比如开始游戏。然后他们可以简单地拖出精灵的框架/主体,然后不再将触摸检测为将启动动作的触摸。
这个实现的问题是,如果用户在播放按钮的 sprite 框架之外拖动,我无法取消按钮的触摸。
您将在下面看到的代码没有场景之间的过渡,因为我想在必须始终退出应用程序以尝试按钮之前测试按钮的可用性。
另外,我已经在 .h 文件中声明了大部分对象。
MenuScene.m 中的代码:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//Touch detection declaration
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self];
touchNode = [self nodeAtPoint:touchLocation];
if([touchNode.name isEqualToString:@"playButton"]){
[playButtonSprite runAction:changePlayButtonTextureON];
}else{}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
if ([touchNode.name isEqualToString:@"playButton"]) {
[playButtonSprite runAction:changePlayButtonTextureOFF];
}
}
我还想知道是否有另一种方法来检测触摸是否在播放按钮精灵节点上。不过,当找到我提到的上一个问题的解决方案时,这可能会得到解决。
【问题讨论】:
标签: ios objective-c xcode ios7 sprite-kit