Ios 精灵套件游戏没有检测到两个同时触碰
我正在开发一款精灵套件游戏,需要对屏幕左侧或右侧的触摸做出反应。我在另一个问题中找到了这个解决方案:Ios 精灵套件游戏没有检测到两个同时触碰,ios,xcode,sprite-kit,Ios,Xcode,Sprite Kit,我正在开发一款精灵套件游戏,需要对屏幕左侧或右侧的触摸做出反应。我在另一个问题中找到了这个解决方案: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint touchLocation = [touch locationInNode:self]; if (touchLocation.x < self.size.width
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self];
if (touchLocation.x < self.size.width / 2.0f) {
touching = YES;
}
if (touchLocation.x > self.size.width / 2.0f) {
[self drawRocket];
}
}
以及
-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event{
UITouch*touch=[触摸任何对象];
CGPoint touchLocation=[触摸位置Innode:self];
用于(UITouch*触摸屏){
如果(触摸位置.xself.size.width/2.0f){
如果(![rocketFlame父级]){
[自燃火箭];
}
}
}
}
我仍然有同样的问题。在初始化方法中添加以下行 self.view.multipleTouchEnabled=是
for (UITouch *touch in touches) {
CGPoint touchLocation = [touch locationInNode:self];
if (touchLocation.x < self.size.width / 2.0f) {
touching = YES;
}
if (touchLocation.x > self.size.width / 2.0f) {
[self drawRocket];
}
}
用于(UITouch*触摸屏){
CGPoint touchLocation=[触摸位置Innode:self];
如果(触摸位置.xself.size.width/2.0f){
[自拔火箭];
}
}
使用鼠标和键盘模拟多点触控手势您正在定义一个局部变量,该变量隐藏用于在触控事件上循环的变量。请参阅下面代码中的注释
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
// The following statement is causing the issue. Delete it.
//UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self];
if (touchLocation.x < self.size.width / 2.0f) {
touching = YES;
}
if (touchLocation.x > self.size.width / 2.0f) {
if (![rocketFlame parent]) {
[self fireRocket];
}
}
}
}
-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event{
用于(UITouch*触摸屏){
//以下语句导致问题。请删除它。
//UITouch*touch=[触摸任何对象];
CGPoint touchLocation=[触摸位置Innode:self];
如果(触摸位置.xself.size.width/2.0f){
如果(![rocketFlame父级]){
[自燃火箭];
}
}
}
}
您需要处理所有触摸,而不仅仅是[触摸任何对象]。。ie在每次触摸上枚举:对于(UITouch*touch in Touchs){..}@LearnCos2D请用代码示例回答,我不确定要更改哪一行。我尝试了此操作,但仍然存在相同的问题。请在循环中尝试触摸位置查看我的编辑,我在两个位置尝试了此操作,但都不起作用。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self];
for (UITouch *touch in touches) {
if (touchLocation.x < self.size.width / 2.0f) {
touching = YES;
}
if (touchLocation.x > self.size.width / 2.0f) {
if (![rocketFlame parent]) {
[self fireRocket];
}
}
}
for (UITouch *touch in touches) {
CGPoint touchLocation = [touch locationInNode:self];
if (touchLocation.x < self.size.width / 2.0f) {
touching = YES;
}
if (touchLocation.x > self.size.width / 2.0f) {
[self drawRocket];
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
// The following statement is causing the issue. Delete it.
//UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self];
if (touchLocation.x < self.size.width / 2.0f) {
touching = YES;
}
if (touchLocation.x > self.size.width / 2.0f) {
if (![rocketFlame parent]) {
[self fireRocket];
}
}
}
}