CC UITouches 忽略第二次触摸

发布于 2024-12-27 13:37:50 字数 490 浏览 4 评论 0原文

我正在尝试使用 UITouch 移动精灵,并且我需要处于多点触摸模式,因为我有一个按钮,在移动精灵时我还需要点击。

问题是,当我错过按钮并用另一根手指敲击屏幕时,第二根手指开始触摸,这导致我的精灵跳跃位置。 任何解决办法。我尝试将按钮放在自己的类中,但这没有帮助。 我之所以不只是将所有代码放入触摸移动中,是因为我正在计算从触摸开始的偏移量。

-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    NSSet *allTouches = [event allTouches];
    switch ([allTouches count]) {
        case 1:{
            NSLog(@"moving touch 1");}break;

所以现在发生的是当我在屏幕上移动手指时 它检测到移动 1 但一旦我放上第二根手指它就停止移动 1 我不想让它停止移动 1

I'm trying to move a sprite around using UITouch and i need to be in multi touch mode because i have a button i also need to hit while i'm moving my sprite around.

The issue is when i miss the button and i hit the screen with my other finger the second finger becomes the touches begins which cause my sprite to jump positions.
Any work around. I tried putting by button in its own class but that didn't help.
The reason why I'm not just putting all the code in touches moved is because I'm calculating the offset from the touches began.

-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    NSSet *allTouches = [event allTouches];
    switch ([allTouches count]) {
        case 1:{
            NSLog(@"moving touch 1");}break;

So now what is happening is when i move my finger across the screen
it detects moving 1 but once i put on the second finger it stops moving 1
i don't want it to stop moving 1

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

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

发布评论

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

评论(2

人│生佛魔见 2025-01-03 13:37:50

在您的 -touchesBegan: 方法中,您是否测试触摸点以查看它是否在图像内部?

In your -touchesBegan: method, are you testing the point of the touch to see if it’s inside the image?

旧情别恋 2025-01-03 13:37:50

在两个按钮触摸上设置一个条件,并且不包含任何其他情况,以避免其他触摸。

喜欢:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSSet *allTouches = [event allTouches];

    switch ([allTouches count]) {
        case 1: {
            CGPoint pos = [[[allTouches allObjects] objectAtIndex:0] locationInView:self];
            // code here for single touch.


        } break;
        case 2: {
            //get out two fingers
            UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];
            // code here for multi touch

        } break;

    }


}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    NSSet *allTouches = [event allTouches];

    switch ([allTouches count])
    {
        case 1: { //Move
            //Single touch


        } break;
        case 2: { //Zoom
            //multi touch

            UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];

            // Code according to you


        } break;

    } 

}

希望这会有所帮助。

put a condition on both button touch and don't include any else case there that will be all to avoid other touches.

Like :

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSSet *allTouches = [event allTouches];

    switch ([allTouches count]) {
        case 1: {
            CGPoint pos = [[[allTouches allObjects] objectAtIndex:0] locationInView:self];
            // code here for single touch.


        } break;
        case 2: {
            //get out two fingers
            UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];
            // code here for multi touch

        } break;

    }


}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    NSSet *allTouches = [event allTouches];

    switch ([allTouches count])
    {
        case 1: { //Move
            //Single touch


        } break;
        case 2: { //Zoom
            //multi touch

            UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];

            // Code according to you


        } break;

    } 

}

Hope this will help.

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