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.
![](http://images.cnitblog.com/blog/292994/201401/232215238199.png)
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.
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.
![](http://images.cnitblog.com/blog/292994/201401/232215238199.png)
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.
相关文章推荐
- Working with Other Node Types
- [ERR] Node 172.168.63.202:7001 is not empty. Either the nodealready knows other nodes (check with CL
- [ERR] Node is not empty. Either the node already knows other nodes (check with C
- Working with specific AutoCAD object types in .NET
- [ERR] Node 192.168.25.128:7111 is not empty. Either the node already knows other nodes (check with C
- Working with Primitive Data Types
- Programming Windows with MFC - Capter 10. Scroll Views, HTML Views, and Other View Types
- [bbk5129]第13集 - Chapter 06- Working with Composite Data Types(Collection)
- Redis学习笔记II-Working with Multiple Databases
- [ERR] Node 192.168.1.77:7000 is not empty. Either the node already knows other nodes (check with CLU
- [bbk5141]第14集 - Chapter 06- Working with Composite Data Types(Collection)
- [ERR] Node 192.168.1.77:7000 is not empty. Either the node already knows other nodes (check with CLU
- 问题:Node 127.0.0.1:6379 is not empty. Either the node already knows other nodes (check with CLUSTER N
- 【LeetCode with Python】 Populating Next Right Pointers in Each Node II
- [ERR] Node 127.0.0.1:7000 is not empty. Either the node already knows other nodes (check with CLUSTE
- Node(16) working with couchDB
- Drupal Working with nodes, content types and fields
- [bbk4998]第11集 - Chapter 06- Working with Composite Data Types -00-4998(Record)
- [bbk5128]第12集 - Chapter 06- Working with Composite Data Types -01-4998(Record)
- [Node.js]32. Level 7: Working with Lists -- Redis