Connecting Physics Bodies
【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:
- Create two physics bodies.
- Attach the physics bodies to a pair of SKNode objects in the scene.
- Create a joint object using one of the subclasses listed in Table 8-3.
- If necessary, configure the joint object’s properties to define how the joint should operate.
- Retrieve the scene’s SKPhysicsWorld object.
- 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.
最新文章
- javascript 中 Promise的使用
- 一些ES5的操作数组的方法
- Anliven - 解决问题的一些方法
- React Native开发技术周报1
- Servicestack IRequestLogger获取 IHttpRequest
- iOS开发MAC下配置Svn和Git
- nginx url自动加斜杠的问题
- mybatis 聚合查询
- JavaScript的事件监听、捕获和冒泡
- mysql select count(filed) 问题(where条件没有数据匹配的话也有数据返回)。
- linux_http协议
- UNIX环境高级编程——创建孤儿进程
- [C++]数组指针,数组引用,函数指针
- element UI Cascader 级联选择器 编辑 修改 数组 路径 问题(转载)
- Linux(以RHEL7为例)下添加工作区的方法|| The Way To Add Workspace On Linux
- Java compiler level does not match the version of the installed Java project facet解决办法
- Linux中apt与apt-get命令的区别与解释
- 【struts2】Action的生命周期
- maven 项目目录图与web 应用结构图对比
- java实现hash一致性算法