gpt4 book ai didi

ios - 多人游戏如何使用多点触控

转载 作者:行者123 更新时间:2023-11-29 04:52:27 27 4
gpt4 key购买 nike

我正在制作一款游戏,两个人在 iPhone 屏幕的两侧移动他们的棋子。我在多点触控部分遇到一些问题,多点触控也设置为打开。这是当前的代码,我需要两个用户能够同时移动,目前只有一个可以。

黄色和绿色是正在移动的两 block (仅在x轴上)

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
touch = [[event touchesForView:self.view] anyObject];
location = [touch locationInView:self.view];
if (location.y > 230) {
locationYellow = location;
yellow.center = CGPointMake(locationYellow.x, yellow.center.y);
}else{
locationGreen = location;
if (VSModeON == YES) {
green.center = CGPointMake(locationGreen.x, green.center.y);
}
}
}

最佳答案

touch = [[event touchesForView:self.view] anyObject]; 

正如听起来的那样,这会从触摸中获取任何对象。此代码通常用于您只期望单次触摸的情况。您当前的代码一次仅处理一次触摸。

对于多点触摸,您需要分析集合中的每个触摸[event attemptsForView:self.view]并采取相应的行动。

所以类似

for (UITouch *aTouch in [event touchesForView:self.view])
{
// Deal with each touch here...
}

关于ios - 多人游戏如何使用多点触控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8584937/

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