Sprite Kit 断言失败:(typeA == b2_dynamicBody || typeB == b2_dynamicBody) [英] Sprite Kit failing assertion: (typeA == b2_dynamicBody || typeB == b2_dynamicBody)

查看:9
本文介绍了Sprite Kit 断言失败:(typeA == b2_dynamicBody || typeB == b2_dynamicBody)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是之前提出的,但原来的提问者不需要更改动态属性,所以他通过取消提问来回答自己的问题.

This was asked earlier, but the original asker didn't need to change the dynamic property so he answered his own question by unasking it.

我在 iOS7 中使用 Sprite Kit,我希望能够在运行时更改 SKPhysicsBody 的动态属性.最初我在 touchesBegan: 方法中改变了它.Apple Dev 论坛中有人建议将更改移至 didSimulatePhysics: 方法,但这也无济于事.

I'm using Sprite Kit in iOS7 and I'd like to be able to change an SKPhysicsBody's dynamic property at runtime. Originally I was changing that in my touchesBegan: method. Someone in the Apple Dev forum suggested moving the change to the didSimulatePhysics: method but that didn't help either.

此代码导致错误:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
  if (!heyWereSwappingDynamismHere) 
  {
    heyWereSwappingDynamismHere = YES;
    SKNode * rope = [self childNodeWithName:@"rope"];
    SKNode * anchor = [rope childNodeWithName:@"anchor"];
    [listOfObjectsToSwapDynamic addObject:anchor];
  }
}

-(void) didSimulatePhysics 
{
  if (heyWereSwappingDynamismHere) 
  {
    for (SKNode * node in listOfObjectsToSwapDynamic) 
    {
        bool isItDynamic = node.physicsBody.isDynamic;
        node.physicsBody.dynamic = !isItDynamic;
    }
    [listOfObjectsToSwapDynamic removeAllObjects];
    heyWereSwappingDynamismHere = NO;
}

}

调试器中出现的错误是:

The error appearing in the debugger is:

断言失败:(typeA == b2_dynamicBody || typeB == b2_dynamicBody),函数 SolveTOI,文件/SourceCache/PhysicsKit/PhysicsKit-4.6/PhysicsKit/Box2D/Dynamics/b2World.cpp,第 670 行.

Assertion failed: (typeA == b2_dynamicBody || typeB == b2_dynamicBody), function SolveTOI, file /SourceCache/PhysicsKit/PhysicsKit-4.6/PhysicsKit/Box2D/Dynamics/b2World.cpp, line 670.

我在别处四处张望,但这似乎是 Sprite Kit 的 Box2D 实现(和覆盖)的问题.

I've looked around elsewhere but this seems to a be a problem with Sprite Kit's implementation (and covering over) of Box2D.

也许?

推荐答案

您可以来回更改 dynamic 属性,但是,如果您使用碰撞/接触检测,则应非常小心.

You can change the dynamic property back and forth, however, you should be very careful if you're using collision/contact detection.

在两个物体之间的碰撞/接触期间,断言其中至少一个必须是动态物体.如果在运行时将该属性更改为 NO,并且另一个接触的物体也是静态的(非动态的),并且正在发生碰撞/接触回调,它将抛出这个特定的断言错误 - 将在 2 个静态物体中间检测到接触-执行,Box2d 不喜欢.

During collision/contact between two bodies, it is asserted that at least one of them must be a dynamic body. If you change that property to NO at runtime, and the other contacted body is also static (non-dynamic), and the collision/contact callback is happening, it will throw this particular assertion error - contact will be detected between 2 static bodies mid-execution, which Box2d doesn't enjoy.

一个可能的解决方法 - 对我有用,甚至直接在 didBeginContact: 方法中:

A possible workaround trick - works for me, even directly in the didBeginContact: method:

SKPhysicsBody *temp = node.physicsBody;
temp.dynamic = NO;
node.physicsBody = temp;

这篇关于Sprite Kit 断言失败:(typeA == b2_dynamicBody || typeB == b2_dynamicBody)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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