作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一款游戏,两个人在 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/
我是一名优秀的程序员,十分优秀!