How a Scene Processes Frames of Animation

  In the traditional view system, the contents of a view are rendered once and then rendered again only when the model’s contents change. This model works very well for views, because in practice most view content is static. Sprite Kit, on the other hand, is designed explicitly for dynamic content. Sprite Kit continuously updates the scene contents and renders it to ensure that animation is smooth and accurate.

  The process of animating and rendering the scene is tied to the scene object (SKScene).

  

Simulating Physics

  To use physics in your game, you need to:

  • Attach physics bodies to nodes in the node tree. See “All Physics is Simulated on Physics Bodies.”
  • Configure the physical properties of the physics bodies. See “Configuring the Physical Properties of a Physics Body.”
  • Define global characteristics of the scene’s physics simulation, such as gravity. See “Configuring the Physics World.”
  • Where necessary to support your gameplay, set the velocity of physics bodies in the scene or apply forces or impulses to them. See “Making Physics Bodies Move.”
  • Define how the physics bodies in the scene interact when they come in contact with each other. See “Working with Collisions and Contacts.”
  • Optimize your phys

All Physics is Simulated on Physics Bodies

  An SKPhysicsBody object defines the shape and simulation parameters for a physics body in the system. When the scene simulates physics, it performs the calculations for all physics bodies connected to the scene tree. So, you create an SKPhysicsBody object, configure its properties, and then assign it to a node’s physicsBody property.

There are three kinds of physics bodies:

  • A dynamic volume simulates a physical object with volume and mass that can be affected by forces and collisions in the system. Use dynamic volumes to represent items in the scene that need to move around and collide with each other.
  • A static volume is similar to a dynamic volume, but its velocity is ignored and it is unaffected by forces or collisions. However, because it still has volume, other objects can bounce off it or interact with it. Use static volumes to represent items that take up space in the scene, but that should not be moved by the simulation. For example, you might use static volumes to represent the walls of a maze.While it is useful to think of static and dynamic volumes as distinct entities, in practice these are two different modes you can apply to any volume-based physics body. This can be useful because you can selectively enable or disable effects for a body.
  • An edge is a static volume-less body. Edges are never moved by the simulation and their mass doesn’t matter. Edges are used to represent negative space within a scene (such as a hollow spot inside another entity) or an uncrossable, invisibly thin boundary. For example, edges are frequently used to represent the boundaries of your scene.The main difference between a edge and a volume is that an edge permits movement inside its own boundaries, while a volume is considered a solid object. If edges are moved through other means, they only interact with volumes, not with other edges.

  

Use a Physics Shape That Matches the Graphical Representation

  when choosing a shape for your physics body, do not be overly precise. More complex shapes require more work to be properly simulated. For volume-based bodies, use the following guidelines:

  • A circle is the most efficient shape.
  • A path-based polygon is the least efficient shape, and the computational work scales with the complexity of the polygon.

An edge-based body is more expensive to compute than a volume-based body. This is because the bodies it interacts with can potentially be on either side of an open edge or on the inside or outside of a closed shape. Use these guidelines:

  • Lines and rectangles are the most efficient edge-based bodies.
  • Edge loops and edge chains are the most expensive edge-based bodies, and the computational work scales with the complexity of the path

Creating an Edge Loop Around the Scene

  Listing 8-1 shows code that is used frequently in games that do not need to scroll the content. In this case, the game wants physics bodies that hit the borders of the scene to bounce back into the gameplay area.

  

Creating a Circular Volume for a Sprite

  Listing 8-2 shows the code that creates the physics body for a spherical or circular object. Because the physics body is attached to a sprite object, it usually needs volume. In this case, the sprite image is assumed to closely approximate a circle centered on the anchor point, so the radius of the circle is calculated and used to create the physics body.

  

  

Advanced Scene Processing的更多相关文章

  1. DotNet 资源大全中文版(Awesome最新版)

    Awesome系列的.Net资源整理.awesome-dotnet是由quozd发起和维护.内容包括:编译器.压缩.应用框架.应用模板.加密.数据库.反编译.IDE.日志.风格指南等. 算法与数据结构 ...

  2. 39. Volume Rendering Techniques

    Milan Ikits University of Utah Joe Kniss University of Utah Aaron Lefohn University of California, D ...

  3. 计算机视觉code与软件

    Research Code A rational methodology for lossy compression - REWIC is a software-based implementatio ...

  4. 【资源大全】.NET资源大全中文版(Awesome最新版)

    算法与数据结构(Algorithms and Data structures) 应用程序接口(API) 应用程序框架(Application Frameworks) 模板引擎(Application ...

  5. Graphics-Processing Architecture Based on Approximate Rendering

    BACKGROUND The present invention generally relates to the processing of graphics data, and particula ...

  6. Windows软件在Linux上的等价/替代/模仿软件列表 (抄一个)

    Last update: 16.07.2003, 31.01.2005, 27.05.2005 您可在以下网站发现本列表最新版:http://www.linuxrsp.ru/win-lin-soft/ ...

  7. SharePoint 2013 版本功能对比

    前言:在SharePoint使用中,经常纠结于版本问题,SharePoint 2013主要有免费的Foundation和收费的标准版.企业版三个版本,他们之间的功能上是不一样的,找了一些资料才发现下面 ...

  8. Oracle Created (Default) Database Users

    http://www.idevelopment.info/data/Oracle/DBA_tips/Database_Administration/DBA_26.shtml DBA Tips Arch ...

  9. Brief Tour of the Standard Library

    10.1. Operating System Interface The os module provides dozens of functions for interacting with the ...

随机推荐

  1. 关于android软键盘enter键的替换与事件监听

    android软键盘事件监听enter键  软件盘的界面替换只有一个属性android:imeOptions,这个属性的可以取的值有 normal,actionUnspecified,actionNo ...

  2. Tyvj 1030 乳草的入侵

    以一个简单的BFS对基础搜索做一个收尾好了. 给一个草,然后以这棵草为九宫格的中心,每周向周围八个方向扩散,问多少个星期能把这个农场占满. 遍历整个map,最后一个出队列的对应的星期数就是所求. // ...

  3. HDU 2122 HDU Today【Floyd】

    题意:给出n条路,起点和终点,问最短距离 用map处理一下地名,再用floyd 可是不懂的是:为什么INF定义成0x7fffffff就输出一堆奇怪的东西,改成100000000就可以了 #includ ...

  4. QCon 2015 阅读笔记 - 团队建设

    QCon 2015阅读笔记 QCon 2015 阅读笔记 - 移动开发最佳实践 QCon 2015 阅读笔记 - 团队建设 中西对话:团队管理的五项理论和实战 - 谢欣.董飞(今日头条,LinkedI ...

  5. Android 编程下两种方式注册广播的区别

    常驻型广播 常驻型广播,当你的应用程序关闭了,如果有广播信息来,你写的广播接收器同样的能接收到,它的注册方式就是在你应用程序的AndroidManifast.xml 中进行注册,这种注册方式通常又被称 ...

  6. 深入理解 AngularJS 的 Scope(转)

    一.遇到的问题 问题发生在使用 AngularJS 嵌套 Controller 的时候.因为每个 Controller 都有它对应的 Scope(相当于作用域.控制范围),所以 Controller ...

  7. mysql应用存储过程批量插入数据

    --批量插入数据的sql语句 delimiter $$ DROP PROCEDURE IF EXISTS `test.sp_insert_batch` $$ CREATE DEFINER =`root ...

  8. phpcms v9 搬家

    1.修改/caches/configs/system.php里面所有和域名有关的,把以前的老域名修改为新域名. 2.进入后台设置--站点管理,对相应的站点的域名修改为新域名. 3.点击后台右上角的更新 ...

  9. AIX 第7章 指令记录

    要点: AIX文件系统的访问路径 AIX文件系统目录树 创建AIX文件系统 文件系统的卸载和删除 文件系统的自动挂载 文件系统的容量管理 文件系统的一致性管理 文件系统的卸载失败 文件系统的快照管理 ...

  10. click和onclick的区别

    onclick是绑定事件,click本身是方法作用是触发onclick事件,只要执行了元素的click()方法,下面有个示例,大家可以看看   Html代码 ? 1 2 3 4 5 6 7 8 9 1 ...