ios Cocos2D Nodes

Base Classes

CCNode继承自CCResponder。CCResponder提供了触摸和其他的输入处理方法。

所有的nodes继承自CCNode。因此nodes拥有CCResponder的所有功能。

Important NodeProperties

最常用的node属性和方法,按照字母排序。

anchorPointPoints:因子用于决定oringin原点的放大和旋转。对于绘制的内容也与nodes的位置有关。可以用来快速定位于node内容的上下左右位置。尽量避免将其作为位置修改器。

contentSizeInPoint:node内容的尺寸大小。{0,0}作为容器的nodes。不考虑子nodes的内容大小。

name:用来鉴定node,使用唯一的名称用来鉴定nodes。

paused:如果为YES,node暂停被集火并且选择器被锁或者选取。子类也被暂停。

physicsBody:node的实质框架。如果node要被psysics控制则创建和分配一个CCPhysicsBody,

physicsNode:返回最近的CCPhysicsNode

positionInPoints:node相对于父node位置的位置。

rotation:相对于父rotation的rotation

scale:相对于父scale的scale

scene:返回一个CCScene实例对象,node作为.的子node为空直到onEnter运行,因此在node初始化编译期间不能使用。

userObject:用来在任何node处存储通用的数据。在node中添加一个collection对象存储任意大小和类型的数据而不用继承作为他的子类。

visiable:如果YES,node将被绘制。实践证明将node设置为隐藏对于重复使用node比回收node再创建一个新的node更有效率。

zOrder:对绘制的顺序有影响。低数值意味着node将会在高的zOrder数值钱被绘制。如果子Node使用的zOrder都是默认的数值0,子node将按照被添加到父node的顺序绘制。

Container Nodes

这些node不能依赖自己绘制任何东西。

CCNode:不可见node,主要用来创建图层或者用来作为其他的node的逻辑可编辑集合。可以用来作为anchor node以实现子node围绕给定点的简单旋转

CCSecne:承载nodes在scene中。可以通过一个选定的动画展示。

CCNodeMultiplexer:类似于CCNode,除了一个子node将被激活(绘制和更新)。你可以在运行时改变激活的node。

CCParallaxNode:基于视差因子以不同的速度移动其子节点。

CCPhysicsNode:允许子node拥有物理特性就是含有一个物理框架。只有父类是CCPhaysicsNode将参与到物理的模拟。你可以改变世界的gravity,允许物理调试绘制,设置冲突回调代理类通过CCPaysicsNode.

CCDrawNode

绘制图元,如点,线,多边形填充和边界(行程)颜色。改变一个原始需要清除整个绘制节点,并再次提交所有的原语。它是最有用的调试绘图。

CCNodeColor

绘制一个方形,用固体颜色填充。

CCNodeGradient

绘制一个填充渐变的矩形。您可以指定开始和结束颜色和梯度的方向。

CCrenderTexure

创建一个包含绘制在渲染纹理上的节点的纹理。创建的纹理可以作为sprite的输入或者图像存入磁盘。常用于创建一个场景的截图或一个场景的节点树的一个分支


CCSprite

绘制一个图片在屏幕上。图像可以绘制的颜色(调色)、倾斜、半透明等效果。CCSprite是使用最频繁的一个node。理论上你可以创建几乎任何游戏完全的精灵,虽然其他节点可能更有效(ccnodecolor,ccnodegradient)或维护(cclabelttf,cclabelbmfont)视情况而定。

CCSprite9Slice

本质上一个sprite将他的图片划分为9个区域,因此取该名称。当中心去不延生至内容的尺寸时,边界区域绘制不会扩大。用于创建用户界面框架,需要能够与无框架的边界变得模糊或混淆的内容延伸。CCSprite9Slice通过用户界面例如CCButton这样的node内部使用。

CCTiledMap

从TMX文件渲染tilemaps。

Renders tilemaps loaded from a TMX file. It can draw orthogonal, isometric and hexagonal tilemaps. A popular tilemap editor isTiled.

Visual Effect Nodes

这些nodes创建了多样的虚拟效果,每一个都可以和另一个关联组合起来。

CCClippingNode

剪切node能够使用任何模板,因此只有模板node的区域是能绘制的或者效果翻转。

CCMotionStreak

用于绘制一条逐渐淡出的线。可以作为一个触摸和拖动指示器。

CCParticleSystem

一个颗粒发射器能够创建颗粒流。颗粒如同缩小版的sprites,但是绘制的速度要快于相同数量的sprits.你可以修改的颗粒发射器的参数来改变动画效果。你不能或者无法修改私有的颗粒在运行状态下,他们也不能拥有物理的身体。

CCProgressNode

一个spirte能够动态的展示给定的完成百分比。sprite能够逐步的填满和展示另一个sprite。这个可以用来载入bar和计时器的冷却。

Label Nodes 

cocos2D 能绘制两个类型的label。:bitmap字体和truetype 字体。

Bitmap Font LabelTrueType Font Label

GlyphsImagesVector Data

Font SizeSet when creating the font, can not be modified at runtime.Can be modified at runtime.

ScalingVia scale property, natural loss in image quality due to scaling artifacts (blur/pixelation or aliasing).By changing font size, no loss in quality.

EffectsOutline, shadow and other effects baked into texture when creating the font.Outline and shadow can be added at runtime at the expense of even greater text change cost. Also supports attributed strings.

Rendering PerformanceComparable to SpritesComparable to Sprites

Text Change PerformanceFast: texture with glyphs already in memory.Slow: old texture discarded, new texture created using iOS font rendering framework.

Memory UsageSize of glyph texture atlas.Each label creates its own texture.

Available FontsMust be created with an external tool and bundled with the app.Built-in truetype fonts (seeiOS font list) plus any custom Truetype font added to app bundle. Custom fonts must be registered in Info.plist (see this Q&A).

Bitmap Font Labels:

Use if you frequently change label text, even if you have just one label whose text changes every frame (ie score, timer) because updating a truetype label's text is very costly.

Use if you have many labels using the same font or very few fonts. Uses less memory than Truetype font labels.

Use if you want a completely custom font made of individual images (see example below).

Truetype Font Labels:

Use if you only need a few labels or for debugging purposes.

Use if you need to be able to scale labels at runtime without loss in quality/readability.

Use if you need a label to be able to change to other truetype fonts at runtime.

Use for static menu text, or where you can create variants of labels up-front so you merely need to change their visible state rather than updating the label text. Updating the text is very slow for Truetype font labels.

Use if you need to use attributed strings, or modify the shadow and outline effects at runtime.

CCLabelBMFont

Draws bitmap fonts. In a bitmap font each character is represented by an image. Bitmap font tools with support for SpriteBuilder & Cocos2D are:

bmGlyph

Glyph Designer

CCLabelTTF

Draws truetype font labels. Each label has its own texture. Every label text change causes the old texture to be discarded and a new texture is created, meaning: aretext changes of truetype labels are very costly!

TTF Labels support attributed strings (iOS 6+) and custom Truetype fonts. Outline and shadow effects can also be added, further increasing the cost of text changes.

User Interface Nodes

The base class for all User Interface nodes isCCControl.

CCButton

A button with a background image (CCSprite9Slice) and a label (CCLabelTTF). When clicked/tapped the button will run a block or selector. The background image and label properties can be modified just like margins and alignment. You can even create buttons with no background nor label (invisible button) and adjust the button's size to a rectangle with custom content that should react to taps/clicks.

CCLayoutBox

Aligns its child nodes either vertically or horizontally. A CCLayoutBox added to another CCLayoutBox with different orientation (one vertical, the other horizontal) enables you to align nodes in a grid.

NoteCCLayoutBox is not suitable for rendering tilemaps. Use CCTiledMap or a number of CCSprite nodes programmatically aligned to a grid.

CCSlider

Draws a slider control which runs a selector or block every time the slider value changes. The slider's background and handle images can be customized. To create vertical sliders simply rotate the slider by 90 or 270 degrees.

CCTextField

Provides a text field for text input. The text field is actually a UITextField/NSTextField with a frame image (CCSprite). Due to the Cocoa (Touch) text field this node should not be scaled, skewed, rotated or it might not draw correctly.

你可能感兴趣的:(ios Cocos2D Nodes)