我正在模擬物理到蛋形SKSprite節點。 但是,斷言失敗的錯誤發生:當使用bodyWithPolygonFromPath時,斷言失敗:蛋形狀的方法
斷言失敗:(edge.LengthSquared()> 1.19209290e-7F * 1.19209290e-7F),功能設置,文件/SourceCache/PhysicsKit_Sim/PhysicsKit-6.5。 4/PhysicsKit/Box2D的/碰撞/型材/ 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];
有什麼不對?任何人都可以幫我解決?非常感謝你!
墜機的原因是雞蛋不是雞蛋;這是一個新月形狀。如果OP在'CGPathAddArc'調用中將NO更改爲YES,它將成爲一個雞蛋,並且應用程序不會崩潰。 – 0x141E