首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IOS从SKPhysicsBody或.xml文件创建.pes

IOS从SKPhysicsBody或.xml文件创建.pes
EN

Stack Overflow用户
提问于 2014-05-10 18:52:20
回答 1查看 110关注 0票数 0

我目前正在制作一个IOS应用程序,我想创建一个定制的SKPhysicsBody。我使用一个编辑器创建了一个.xml文件,其中包含了我所使用的点的坐标。有什么办法从这些点创造一个物理体吗?我用雪碧试剂盒。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-11 08:29:41

我能够用以下代码重新创建物理体:

代码语言:javascript
复制
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行,所以我不得不改变物理体。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23585011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档