Connecting Physics Bodies

  The kinds of joints you can create in Sprite Kit.

  

  

  You add or remove joints using the physics world. When you create a joint, the points that connect the joint are always specified in the scene’s coordinate system. This may require you to first convert from node coordinates to scene coordinates before creating a joint.

To use a physics joint in your game, follow these steps:

  1. Create two physics bodies.
  2. Attach the physics bodies to a pair of SKNode objects in the scene.
  3. Create a joint object using one of the subclasses listed in Table 8-3.
  4. If necessary, configure the joint object’s properties to define how the joint should operate.
  5. Retrieve the scene’s SKPhysicsWorld object.
  6. Call the physics world’s addJoint: method.

Searching for Physics Bodies

  Sometimes, it is necessary to find physics bodies in the scene. For example, you might need to:

  • Discover whether a physics body is located in a region of the scene.
  • Detect when a physics body (such as the one controlled by the player) crosses a particular line.
  • Trace the line of sight between two physics bodies, to see whether another physics body, such as a wall, is interposed between the two objects.

  In some cases, you can implement these interactions using the collisions and contacts system. For example, to discover when a physics body enters a region, you could create a physics body and attach it to an invisible node in the scene. Then, configure the physics body’s collision mask so that it never collides with anything, and its contact mask to detect the physics bodies you are interested in. Your contact delegate is called when the desired interactions occur.

  You can use physicalsworld's [bodyAlongRayStart:end:] to get the body between start & end.

  And you can also use bodyAtPoint: and bodyInRect: to get bodies at point or in rect.

Most Physics Properties Are Dynamic, so Adapt Them at Runtime

  As an object moves throughout the scene, you adjust its linear and rotational damping based on the medium it is in. For example, when the object moves into water, you update the properties to match.

最新文章

  1. javascript 中 Promise的使用
  2. 一些ES5的操作数组的方法
  3. Anliven - 解决问题的一些方法
  4. React Native开发技术周报1
  5. Servicestack IRequestLogger获取 IHttpRequest
  6. iOS开发MAC下配置Svn和Git
  7. nginx url自动加斜杠的问题
  8. mybatis 聚合查询
  9. JavaScript的事件监听、捕获和冒泡
  10. mysql select count(filed) 问题(where条件没有数据匹配的话也有数据返回)。
  11. linux_http协议
  12. UNIX环境高级编程——创建孤儿进程
  13. [C++]数组指针,数组引用,函数指针
  14. element UI Cascader 级联选择器 编辑 修改 数组 路径 问题(转载)
  15. Linux(以RHEL7为例)下添加工作区的方法|| The Way To Add Workspace On Linux
  16. Java compiler level does not match the version of the installed Java project facet解决办法
  17. Linux中apt与apt-get命令的区别与解释
  18. 【struts2】Action的生命周期
  19. maven 项目目录图与web 应用结构图对比
  20. java实现hash一致性算法

热门文章

  1. SQLite及ORMlite在WebApp中的使用
  2. Qt之设置QWidget背景色
  3. js数组的声明与应用
  4. iOS中第三方框架刷新
  5. android layoutparams应用指南(转)
  6. matlab数据的导入和导出,以matlab工作区workspace为source和destination
  7. Eclipse无法识别小米2S手机
  8. 在Ubuntu中用root帐号登录
  9. 嵌入式 GDB调试死锁示例
  10. PreferenceActivity使用方法