Sprite Kit - 将两个物理实体添加到一个SKNode [英] Sprite Kit - Adding two physics bodies to one SKNode

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

问题描述

是否可以将两个(更多)SKPhysicsBodys添加到一个SKNode?类似于:
PhysicsEditor的示例
因为角色的头部应该与球碰撞,顶部应该是圆的。此外球不能通过球员。你知道如何实现这个目标吗?

Is it possible to add two (ore more) SKPhysicsBodys to one SKNode? Something similar to this: Example from PhysicsEditor Because the head of the character should collide with a ball, the top should be round. Furthermore the ball mustn't go through the player. Do you have an idea how to accomplish this?

推荐答案

作为 physicsBody 属性 SKNode 表明,节点和物理机构之间存在一对一的关系。

As the physicsBody property on SKNode suggests, there's a one-to-one relationship between nodes and physics bodies.

但是,这并不意味着你必须为每个可见的精灵都有一个基本的形状。您可以采取一些方法来完成您正在寻找的内容:

However, that doesn't mean you have to have one basic shape for every visible sprite. There are a few approaches you can take to accomplish what you're looking for:


  • 顶部是否真的需要舍入?你可以用矩形覆盖大部分猴子艺术品。 (我认为你想要一个圆顶,所以碰撞会在不同方向反弹。)

  • 创建使用多边形后的圆头矩形形状。您必须选择一些边来近似适合您应用的曲线:太多而且它会减慢物理模拟的速度,太少而且当其他物体反弹时它不会像圆圈一样。

  • 每个人都需要一个节点,但不是每个节点都需要一个可见的精灵。你可以用两个节点制作你的猴子:一个拥有艺术并且附有方形或圆形物理体的节点,另一个节点具有另一个物理体,通过固定关节连接,
    但没有艺术。

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

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