gpt4 book ai didi

ios - 使用bodyWithPolygonFromPath:方法对蛋形进行声明时断言失败

转载 作者:行者123 更新时间:2023-12-01 19:01:29 24 4
gpt4 key购买 nike

我正在将物理模拟为蛋形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];

怎么了?谁能帮我修复?非常感谢你!

最佳答案

根据断言,边缘之一比sprite工具包预期的最小大小短。

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

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

关于ios - 使用bodyWithPolygonFromPath:方法对蛋形进行声明时断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22613663/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com