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.

  • 相关阅读:
    ReentrantLock实现原理分析
    《亿级流量网站架构核心技术》概要
    Java日志框架:logback详解
    40个Java多线程问题总结
    使用Jenkins部署Spring Boot项目
    spring security 实践 + 源码分析
    Spring Boot使用过滤器和拦截器分别实现REST接口简易安全认证
    Spring Boot+redis存储session,满足集群部署、分布式系统的session共享
    maven-assembly-plugin的使用
    使用maven构建多模块项目,分块开发
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3533208.html
Copyright © 2011-2022 走看看