Working with Sprites

Working with Sprites

 1、An SKSpriteNode object can be drawn either as a rectangle with a texture mapped onto it or as a colored, untextured rectangle.

  SpriteNode可以是一个包含了texture的结点也可以是一个无texture的色块。

 2、anchorPoint属性用于指定中心位置(旋转轴),默认是(0.5,0.5)。

 3、centerRect属性用于实现拉伸的九宫格。The default value is a rectangle that covers the entire texture。

 4、color和colorBlendFactor用于实现node颜色与texture颜色的混合。The color blend factor defaults to 0.0。

 5、blendMode用于决定与framebuffer中颜色的混合方式。

 6、TextureAtlas用于用于将多个texture聚合为一张图。

 7、preloadTexture方法用于预加载函数。

Texture Atlas

  To avoid making multiple drawing passes, Sprite Kit uses texture atlases to collect related images together. You specify which assets should be collected together, and Xcode builds a texture atlas automatically. Then, when your game loads the texture atlas, Sprite Kit manages all the images inside the atlas as if they were a single texture. You continue to use SKTextureobjects to access the elements contained in the atlas.

  During build time, the compiler looks for any folders with the naming format of name.atlas. After those folders have been identified, all of the images within the folders are combined into one or more large image files. Texture atlases are automatically available to apps that include the Sprite Kit framework.

  After the app is built, new folders are created with a .atlasc suffix and placed in your app bundle’s Resource folder. Those new images are automatically rotated and trimmed to fit the maximum number of images into a single file, one whose images and orientation are tracked by a property list (.plist) associated with the folder. You do not need to change your code in order to use the texture atlas feature.

  When generating the .atlasc folders and image files, the following rules apply:

  • Each compiled image has a maximum size of 2000 x 2000 pixels.

  • After an image has reached its maximum size, a new image is created.

  • Images for the same device are kept together—for example, all iPhone images are in one file (~iphone.1.png), and all iPad images are in another file (-ipad.1.png).

Adding Actions to Nodes

 1、结点的runAction方法用于启动一个action。

 2、runAction:withKey:给action定义一个名字,用于以后引用。

 3、组合类型有3种,sequence、group(Run Actions in Parallel)、repeating action。

 4、The wait action is a special action that is usually used only in sequences. This action simply waits for a period of time and then ends, without doing anything; you use them to control the timing of a sequence.

  SKAction *wait = [SKAction waitForDuration: 0.5];

 5、The removeNode action is an instantaneous action, so it takes no time to execute. You can see that although this action is part of the sequence, it does not appear on the timeline in Figure 3-1. As an instantaneous action, it begins and completes immediately after the fade action completes. This action ends the sequence.

  SKAction *removeNode = [SKAction removeFromParent];

 6、Call the nodeAtPoint: method to find the first descendant that intersects the point, or use thenodesAtPoint: method to receive an array of all of the nodes that intersect the point.

Building Your Scene

 1、可以通过z值或默认以顺序来显示node,ignoreSiblingOrder可以指定不管list-order。

 2、高级搜索通过提供\,\\,*来提供更高级的node查找服务。

Transitioning Between Two Scenes

 1、使用SKTransition的示例:

  Working with Sprites

  When the transition occurs, the scene property is immediately updated to point to the new scene. Then, the animation occurs. Finally, the strong reference to the old scene is removed. If you need to keep the scene around after the transition occurs, your app needs to keep its own strong reference to the old scene.

 2、pausesIncomingScene & pausesOutgoingScene 决定在场景转换时,动画是否继续。

 3、willMoveFromView & didMoveToView,用于监测scene被加载/移除到一个SKView。

上一篇:SLAM中的EKF,UKF,PF原理简介


下一篇:bzoj5100 [POI2018]Plan metra 构造