我必须创建一个 CGPathRef 来模拟 Sprite Kit 中的物理属性。
我正在尝试通过一半圆形加上一半椭圆形来创建一个蛋形路径。鸡蛋的比例为 0.4(半圆形底部)到 0.6(半椭圆形顶部);但是,我不知道为什么什么也没发生。以下代码是路径的创建:
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;
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, 0, self.egg.size.height*0.4, self.egg.size.width/2, M_PI, M_PI_2, NO);
CGPathAddEllipseInRect(path, NULL, self.egg.frame);
self.egg.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromPath:path];
self.egg.physicsBody.dynamic = YES;
self.egg.physicsBody.categoryBitMask = eggCategory;
self.egg.physicsBody.contactTestBitMask = floorCategory;
self.egg.physicsBody.collisionBitMask = floorCategory;
//self.eggCanMove = NO;
self.egg.physicsBody.allowsRotation = YES;
[self addChild:self.egg];