我目前正在制作一个IOS应用程序,我想创建一个定制的SKPhysicsBody。我使用一个编辑器创建了一个.xml文件,其中包含了我所使用的点的坐标。有什么办法从这些点创造一个物理体吗?我用雪碧试剂盒。
发布于 2014-05-11 08:29:41
我能够用以下代码重新创建物理体:
CGFloat offsetX = sprite.frame.size.width * sprite.anchorPoint.x;
CGFloat offsetY = sprite.frame.size.height * sprite.anchorPoint.y;
CGMutablePathRef spritePath = CGPathCreateMutable();
CGPathMoveToPoint(spritePath, NULL, 3 - offsetX, 1 - offsetY);
CGPathAddLineToPoint(spritePath, NULL, 1 - offsetX, 3 - offsetY);
CGPathAddLineToPoint(spritePath, NULL, 1 - offsetX, 6 - offsetY);
CGPathAddLineToPoint(spritePath, NULL, 6 - offsetX, 7 - offsetY);
CGPathAddLineToPoint(spritePath, NULL, 7 - offsetX, 10 - offsetY);
CGPathAddLineToPoint(spritePath, NULL, 19 - offsetX, 9 - offsetY);
CGPathAddLineToPoint(spritePath, NULL, 20 - offsetX, 7 - offsetY);
CGPathAddLineToPoint(spritePath, NULL, 14 - offsetX, 6 - offsetY);
CGPathAddLineToPoint(spritePath, NULL, 11 - offsetX, 5 - offsetY);
CGPathAddLineToPoint(spritePath, NULL, 9 - offsetX, 5 - offsetY);
CGPathAddLineToPoint(spritePath, NULL, 9 - offsetX, 2 - offsetY);
CGPathAddLineToPoint(spritePath, NULL, 8 - offsetX, 1 - offsetY);
sprite.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:spritePath];我手动输入坐标,它就能工作了!然而,我相信物理体只限于12行,所以我不得不改变物理体。
https://stackoverflow.com/questions/23585011
复制相似问题