Sprite Kit:一个节点有两个物理体 [英] Sprite Kit: One node with two physics body

查看:49
本文介绍了Sprite Kit:一个节点有两个物理体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个节点有可能有两条物理体路径吗?我想创建一个节点,该节点的两侧有两个(圆形)物理体.

It's possible for one node to have two physics body paths? I want to create a node that has two (circle) physics bodies on the sides of the node.

如果不可能,是否有任何解决方法来实现这一目标?谢谢

If it's not possible, is there are any workaround to achieve that? thank you

推荐答案

您想使用 [SKPhysicsBody bodyWithBodies:...].来自 文档:

传递给该方法的物理体的形状用于创建一个新的物理体,其覆盖区域是区域的联合它的孩子们.这些区域不需要是连续的.如果有两个部分之间的空间,其他身体可能能够通过这些部分.但是,物理体被视为单个连接的身体,意味着施加在身体上的力或冲动影响所有的碎片,就好像它们用一个坚不可摧的框架.

The shapes of the physics bodies passed into this method are used to create a new physics body whose covered area is the union of the areas of its children. These areas do not need to be contiguous. If there is space between two parts, other bodies may be able to pass between these parts. However, the physics body is treated as a single connected body, meaning that a force or impulse applied to the body affects all of the pieces as if they were held together with an indestructible frame.

它看起来像这样:

SKPhysicsBody *leftCircle = [SKPhysicsBody bodyWithCircleOfRadius:leftCircleRadius center:leftCircleCenter];
SKPhysicsBody *rightCircle = [SKPhysicsBody bodyWithCircleOfRadius:rightCircleRadius center:rightCircleCenter];

node.physicsBody = [SKPhysicsBody bodyWithBodies:@[leftCircle, rightCircle]];

这篇关于Sprite Kit:一个节点有两个物理体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆