zoukankan      html  css  js  c++  java
  • 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:

    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.

  • 相关阅读:
    SHELL变量
    LA 2797
    计算几何-圆 模板 训练指南267
    hdu 2553 八皇后问题 基础
    CodeForces 557C Arthur and Table STL的使用
    LA 3263 好看的一笔画 欧拉几何+计算几何模板
    UVA 11178 Morley's Theorem 计算几何模板
    poj 1113
    poj 2187 Beauty Contest 凸包模板+求最远点对
    hdu 1081 dp问题:最大子矩阵和
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3533208.html
Copyright © 2011-2022 走看看