游戏中启用多点触控吗?

发布于 2024-10-14 17:32:52 字数 231 浏览 1 评论 0原文

我正在 Xcode 中创建一个简单的乒乓球游戏。我有一个 2 人版本,两个桨都可以移动并且功能完美。游戏完美无缺,只是你不能同时移动两个桨,导致 2 人模式毫无用处。

如何使两个桨同时移动? 我已经尝试在 Interface Builder 中选择“多点触摸”按钮,但它什么也没做,而且我不太确定它是否是我想要的启用多点触摸的正确途径。

另外,如果这很重要的话,我的游戏是基于视图的应用程序。

谢谢!

I am creating a simple pong game in Xcode. I have a 2 player version and both paddles can be moved and function perfectly. The game is flawless except for the fact that you cannot move both paddles at the same time, rendering the 2 player mode useless.

How can I enable both paddles to be moved at the same time?
I've already tried selecting the "Multiple Touch" button in Interface Builder but it does nothing and im not quite sure it is even the correct route into enabling multi touch as I want it.

Also, my game is a View-Based Application if that matters.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷路的信 2024-10-21 17:32:52

编辑:我读错了问题。添加了代码片段。

这是当我收到touchesBegan事件时用来提取所有触摸的代码:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSArray *touchesArray = [touches allObjects];
    NSUInteger nNumTouches = [touchesArray count];
    UITouch *touch;
    CGPoint ptTouch;
    for (int nTouch = 0;  nTouch < nNumTouches;  nTouch++)
    {
        touch = [touchesArray objectAtIndex:nTouch];
        ptTouch = [touch locationInView:self.view];

        // Do stuff with the touch
    }
}

对于touchesEnded和touchesMoved也类似

EDIT: I mis-read the question. Added code snippet.

Here's the code I use to extract all touches when I get a touchesBegan event:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSArray *touchesArray = [touches allObjects];
    NSUInteger nNumTouches = [touchesArray count];
    UITouch *touch;
    CGPoint ptTouch;
    for (int nTouch = 0;  nTouch < nNumTouches;  nTouch++)
    {
        touch = [touchesArray objectAtIndex:nTouch];
        ptTouch = [touch locationInView:self.view];

        // Do stuff with the touch
    }
}

and similarly for touchesEnded and touchesMoved

靖瑶 2024-10-21 17:32:52

根据我的经验(不是那么多)。您可以为 2 个桨创建 2 个 UIView,触摸一个视图将移动一个桨,而触摸另一个视图将移动另一个桨。我希望这有帮助。

如果您不知道如何拆分视图,您可以简单地让它识别 2 个触摸,

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch1 = [[event touchesForView:zone1] anyObject];
UITouch *touch2 = [[event touchesForView:zone2] anyObject];
if (touch1)
    touchOffset1 = paddle1.center.x - [touch1 locationInView:touch1.view].x;
if (touch2)
    touchOffset2 = paddle2.center.x - [touch2 locationInView:touch2.view].x;
}

您可以使用这个,它可能不是最有效的,但如果您不知道如何拆分触摸,它确实有效。

From my experience (which isn't that much). You can create 2 UIViews for the 2 paddles, touching in one view will move one paddle, while touching in the other will move the other paddle. I hope this helps.

If you don't know how to split the views, you can simply make it identify 2 touches

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch1 = [[event touchesForView:zone1] anyObject];
UITouch *touch2 = [[event touchesForView:zone2] anyObject];
if (touch1)
    touchOffset1 = paddle1.center.x - [touch1 locationInView:touch1.view].x;
if (touch2)
    touchOffset2 = paddle2.center.x - [touch2 locationInView:touch2.view].x;
}

This you can use, it probably isn't the most productive, but it does work if you can't figure out how to split the touches.

美煞众生 2024-10-21 17:32:52
self.view.multipleTouchEnabled = YES;

默认为否

self.view.multipleTouchEnabled = YES;

by default it is No

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文