1

我正在将物理模拟为蛋形 SKSprite 节点。但是,发生断言失败错误:

断言失败:(edge.LengthSquared() > 1.19209290e-7F * 1.19209290e-7F),函数集,文件 /SourceCache/PhysicsKit_Sim/PhysicsKit-6.5.4/PhysicsKit/Box2D/Collision/Shapes/b2PolygonShape.cpp,第 180 行.

以下是代码:

self.egg = [SKSpriteNode spriteNodeWithImageNamed:IMAGE_NAME_EGG];
    [self.egg setScale:0.2];
    self.egg.position = CGPointMake(self.size.width/2,self.size.height - self.egg.size.height/2);
    self.egg.name = IMAGE_NAME_EGG;

    CGPoint startPoint = CGPointMake(0, self.egg.size.height*0.4);
    CGPoint endPoint = CGPointMake(self.egg.size.width, startPoint.y);
    CGPoint controlPointLeft = CGPointMake(startPoint.x, self.egg.size.height);
    CGPoint controlPointRight = CGPointMake(endPoint.x, controlPointLeft.y);


    CGMutablePathRef pathRef = CGPathCreateMutable();        
    CGPathMoveToPoint(pathRef, NULL, startPoint.x, startPoint.y);
    CGPathAddQuadCurveToPoint(pathRef, NULL, controlPointLeft.x, controlPointLeft.y, self.egg.size.width/2, controlPointLeft.y);
    CGPathAddQuadCurveToPoint(pathRef, NULL, controlPointRight.x, controlPointRight.y, endPoint.x,endPoint.y);
    CGPathAddArc(pathRef, NULL, self.egg.size.width/2, startPoint.y, self.egg.size.width/2, 0, M_PI, NO);

    self.egg.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:pathRef];
    self.egg.physicsBody.dynamic = YES;
    self.egg.physicsBody.categoryBitMask = eggCategory;
    self.egg.physicsBody.contactTestBitMask = rabbitCategory;
    self.egg.physicsBody.collisionBitMask = rabbitCategory;
    self.egg.physicsBody.allowsRotation = YES;
    [self addChild:self.egg];

怎么了?谁能帮我解决?非常感谢!

4

3 回答 3

2

当您使用“bodyWithPolygonFromPath:”时,您必须确保路径满足以下条件:

1)。凸多边形路径 2)。逆时针绕线 3). 没有自相交。//这些点是相对于拥有节点的原点指定的。

您可以在此处在 SKPhysicsBody 的应用类参考中找到它: https ://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKPhysicsBody_Ref/Reference/Reference.html#//apple_ref/occ/clm/SKPhysicsBody/ bodyWithPolygonFromPath

于 2014-03-31T13:30:42.603 回答
1

根据断言,其中一条边短于 sprite kit 预期的最小尺寸。

Assertion failed: (edge.LengthSquared() > 1.19209290e-7F * 1.19209290e-7F)

检查您的路径坐标并确保它不会太小。

于 2014-03-24T22:56:43.130 回答
0

尝试制作三角形路径时,我在较旧的 iOS7 iPhone 上遇到此错误。事实证明,添加最后一行以将路径带回起点会导致错误(尽管较新的 iOS 版本允许这样做。)IE:

CGPathMoveToPoint(path, nil, self.size.width/2, self.size.height/2)
CGPathAddLineToPoint(path, nil, -self.size.width/2, 0.0)
CGPathAddLineToPoint(path, nil, self.size.width/2, -self.size.height/2)
CGPathAddLineToPoint(path, nil, self.size.width/2, self.size.height/2) //REMOVED THIS LINE TO FIX
CGPathCloseSubpath(path)

这就解释了为什么有一条边太小而无法评估——两个相同点之间的边是 0!

于 2014-12-31T04:30:16.257 回答