[英]how to make multi touch enabled ios app
I have made an app and i want to make it multi touch compatible. 我做了一个应用程序,我想使其与多点触控兼容。 i have tried looking around but the answers aren't specific to mine.
我曾尝试环顾四周,但答案并非特定于我。 Here is what i do:
这是我的工作:
1) My coding: 1)我的编码:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesMoved:touches withEvent:event];
if (gameState == kGameStatePaused) {(gameState = kGameStateRunning);}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if(gameState == kGameStateRunning) {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
if(location.x > 400) {
CGPoint yLocation = CGPointMake(playerPaddle.center.x, location.y);
playerPaddle.center = yLocation;
}
if (gameStyle == kGameStyleTwoP) {
if(location.x < 100) {
CGPoint yLocation2 = CGPointMake(computerPaddle.center.x, location.y);
computerPaddle.center = yLocation2;
}
}
}
2) I have gone onto Interface Builder and checked the box for multitouch enabled 2)我已经进入Interface Builder并选中了启用多点触摸的复选框
3) I build and run my app and it opens properly and when i go to test the multitouch i hold "option key" and click and move the mouse 3)我构建并运行我的应用程序,它会正确打开,当我去测试多点触控时,我按住“选项键”并单击并移动鼠标
4) (i am trying to make computerPaddle and playerPaddle both move) but only one of the works at a time 4)(我正在尝试使computerPaddle和playerPaddle都移动),但一次只能进行一项操作
I have to tried to fix it but i can't understand where i am going wrong. 我必须尝试修复它,但我不明白我要去哪里。
Any help is useful. 任何帮助都是有用的。 THX.
谢谢。
There is a property named multipleTouchEnabled
on the UIView that you can set to YES to enable it (defaults NO). UIView上有一个名为
multipleTouchEnabled
的属性,您可以将其设置为YES以启用它(默认为NO)。
Also, you should loop to treat all touches in the touches
set that you receive in touchesMoved
. 同样,您应该循环处理在
touchesMoved
收到的touches
集中的所有触摸。
look this line 看这条线
UITouch *touch = [[event allTouches] anyObject];
you only take one touch and ignore rest and thats why only one thing can move 您只需要轻轻一按,就忽略休息,这就是为什么只有一件事可以移动的原因
so replace with a for loop should fix the problem 所以用for循环替换应该可以解决问题
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if(gameState == kGameStateRunning) {
for (UITouch *touch in [event allTouches]) {
CGPoint location = [touch locationInView:touch.view];
if(location.x > 400) {
CGPoint yLocation = CGPointMake(playerPaddle.center.x, location.y);
playerPaddle.center = yLocation;
}
if (gameStyle == kGameStyleTwoP) {
if(location.x < 100) {
CGPoint yLocation2 = CGPointMake(computerPaddle.center.x, location.y);
computerPaddle.center = yLocation2;
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.