gpt4 book ai didi

iphone - 如何制作启用多点触控的ios应用

转载 作者:行者123 更新时间:2023-12-01 17:18:42 24 4
gpt4 key购买 nike

我做了一个应用程序,我想使其兼容多点触控。我曾尝试环顾四周,但答案并非特定于我。
这是我的工作:

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)我已经进入Interface Builder并选中了启用多点触摸的复选框

3)我构建并运行我的应用程序,它会正确打开,当我去测试多点触控时,我按住“选项键”并单击并移动鼠标

4)(我正在尝试使computerPaddle和playerPaddle都移动),但一次只能进行一项操作

我必须尝试修复它,但我不明白我要去哪里。

任何帮助都是有用的。
谢谢。

最佳答案

看这条线

UITouch *touch = [[event allTouches] anyObject];

您只需要轻轻一按,就忽略休息,这就是为什么只有一件事可以移动的原因

所以用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;
}
}
}
}

关于iphone - 如何制作启用多点触控的ios应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10833718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com