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.
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.
This code causes the error:
-(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:
Assertion failed: (typeA == b2_dynamicBody || typeB == b2_dynamicBody), function SolveTOI, file /SourceCache/PhysicsKit/PhysicsKit-4.6/PhysicsKit/Box2D/Dynamics/b2World.cpp, line 670.
I've looked around elsewhere but this seems to a be a problem with Sprite Kit's implementation (and covering over) of Box2D.
Maybe?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…