您的位置:首页 > Web前端 > Node.js

Working with Other Node Types II

2014-01-23 22:26 405 查看
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.

  


  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:

Draws its children into a private framebuffer.

Applies a Core Image effect to the private framebuffer. This stage is optional.

Blends the contents of its private framebuffer into its parent’s framebuffer, using one of the standard sprite blend modes.

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: