Working with Other Node Types II

Working with Other Node Types II

  An SKCropNode object does not directly render content, like a sprite node. Instead, it alters the behavior of its children when they are rendered. A crop node crops out portions of the content rendered by the children.

  Listing 6-8 shows a simple use of a mask. This code loads a mask image from a texture in the app bundle. A portion of the scene’s content is then rendered, using the mask to prevent it from overdrawing the portion of the screen that the game uses to show controls.

  Working with Other Node Types II

  When the crop node is rendered, the mask is rendered before the descendants are drawn. Only the alpha component of the resulting mask is relevant. Any pixel in the mask with an alpha value of 0.05 or higher is rendered. All other pixels are cropped.

Effect Nodes Apply Special Effects to Their Descendants

  An SKEffectNode object does not draw content of its own. Instead, each time a new frame is rendered using the effect node, the effect node follows these steps:

  1. Draws its children into a private framebuffer.
  2. Applies a Core Image effect to the private framebuffer. This stage is optional.
  3. Blends the contents of its private framebuffer into its parent’s framebuffer, using one of the standard sprite blend modes.
  4. Discards its private framebuffer.

  You’ve learned a lot about the SKScene class already, but you may not have noticed that it is a subclass of SKEffectNode. This means that any scene can apply a filter to the contents. Although applying filters can be very expensive—not all filters are well designed for interactive effects—experimentation can help you find some interesting ways to use filters.

  If the content of the effect node is static, you can set the node’s shouldRasterize property to YES. Setting this property causes the following changes in behavior:

  • The framebuffer is not discarded at the end of rasterization. This also means that more memory is being used by the effect node, and rendering may take slightly longer.
  • When a new frame is rendered, the framebuffer is rendered only if the content of the effect node’s descendants have changed.
  • Changing the Core Image filter’s properties no longer causes the framebuffer to automatically be updated. You can force it to be updated by setting the shouldRasterize property to NO.

Working with Other Node Types II

上一篇:求根号m(巴比伦算法)


下一篇:注册dll