关于spriteKit中联系人的双重通知 [英] Double notification on contact in spriteKit

查看:106
本文介绍了关于spriteKit中联系人的双重通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的SKSpriteNode点击与worldCategory接触时,我似乎得到双重通知,这是怎么回事?当我想触摸worldCategory时想要运行一个动作会产生问题,因为动作正在被触发

I seem to get a double notification when my SKSpriteNode hits has contact with the worldCategory, how come is this? This creates problem when i want to run an action when it touches the worldCategory, since the action is being triggered

这是我在InitWithSize方法中的位掩码

Here is my bitmask in the InitWithSize method

    mover.physicsBody.categoryBitMask = birdCategory;
    bottom.physicsBody.categoryBitMask = worldCategory;

    mover.physicsBody.contactTestBitMask = worldCategory;

以下是联系方式:

- (void)didBeginContact:(SKPhysicsContact *)contact {
if (contact.bodyA.categoryBitMask == worldCategory) {



    mover.texture = [SKTexture textureWithImageNamed:@"birddead1"];
    NSLog(@"Contact");





    self.scene.paused = YES;
    [pauseButton removeFromSuperview];



}
}

在我的日志中显示两行联系人

In my log there is being shown two lines with "Contact"

推荐答案

设置对象的恢复原状属性为零如下:

Set your object's restitution property to zero like this:

self.physicsBody.restitution = 0;  //it's either self or the name of your object

如果这不能解决您的问题,请查看与您的对象相关的移动代码。查找导致来回移动的任何情况,这可能会造成双重联系问题。

If that does not solve your issue, look at the movement code related to your object(s). Look for any situation that cause a 'back and forth' movement which can create the double contact issue.

作为最后的手段,您可以为联系人设置过滤器:

As a last resort you can set up a filter for your contacts:


  1. 创建一个存储联系时间的变量。

  2. 比较联系变量时间更新中的当前时间:方法。

  3. 如果差异小于指定时间(例如0.2秒),则允许联系人并将您的联系时间变量设置为当前时间。如果差异低于过滤时间(0.2秒),请忽略该联系。

这篇关于关于spriteKit中联系人的双重通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆