ios Cocos2D Nodes

Base Classes

CCNode繼承自CCResponder。CCResponder提供了觸摸和其他的輸入處理方法。

所有的nodes繼承自CCNode。因此nodes擁有CCResponder的所有功能。

Important NodeProperties

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

anchorPointPoints:因子用于決定oringin原點(diǎn)的放大和旋轉(zhuǎn)。對于繪制的內(nèi)容也與nodes的位置有關(guān)??梢杂脕砜焖俣ㄎ挥趎ode內(nèi)容的上下左右位置。盡量避免將其作為位置修改器。

contentSizeInPoint:node內(nèi)容的尺寸大小。{0,0}作為容器的nodes。不考慮子nodes的內(nèi)容大小。

name:用來鑒定node,使用唯一的名稱用來鑒定nodes。

paused:如果為YES,node暫停被集火并且選擇器被鎖或者選取。子類也被暫停。

physicsBody:node的實(shí)質(zhì)框架。如果node要被psysics控制則創(chuàng)建和分配一個(gè)CCPhysicsBody,

physicsNode:返回最近的CCPhysicsNode

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

rotation:相對于父rotation的rotation

scale:相對于父scale的scale

scene:返回一個(gè)CCScene實(shí)例對象,node作為.的子node為空直到onEnter運(yùn)行,因此在node初始化編譯期間不能使用。

userObject:用來在任何node處存儲通用的數(shù)據(jù)。在node中添加一個(gè)collection對象存儲任意大小和類型的數(shù)據(jù)而不用繼承作為他的子類。

visiable:如果YES,node將被繪制。實(shí)踐證明將node設(shè)置為隱藏對于重復(fù)使用node比回收node再創(chuàng)建一個(gè)新的node更有效率。

zOrder:對繪制的順序有影響。低數(shù)值意味著node將會在高的zOrder數(shù)值錢被繪制。如果子Node使用的zOrder都是默認(rèn)的數(shù)值0,子node將按照被添加到父node的順序繪制。

Container Nodes

這些node不能依賴自己繪制任何東西。

CCNode:不可見node,主要用來創(chuàng)建圖層或者用來作為其他的node的邏輯可編輯集合??梢杂脕碜鳛閍nchor node以實(shí)現(xiàn)子node圍繞給定點(diǎn)的簡單旋轉(zhuǎn)

CCSecne:承載nodes在scene中??梢酝ㄟ^一個(gè)選定的動畫展示。

CCNodeMultiplexer:類似于CCNode,除了一個(gè)子node將被激活(繪制和更新)。你可以在運(yùn)行時(shí)改變激活的node。

CCParallaxNode:基于視差因子以不同的速度移動其子節(jié)點(diǎn)。

CCPhysicsNode:允許子node擁有物理特性就是含有一個(gè)物理框架。只有父類是CCPhaysicsNode將參與到物理的模擬。你可以改變世界的gravity,允許物理調(diào)試?yán)L制,設(shè)置沖突回調(diào)代理類通過CCPaysicsNode.

CCDrawNode

繪制圖元,如點(diǎn),線,多邊形填充和邊界(行程)顏色。改變一個(gè)原始需要清除整個(gè)繪制節(jié)點(diǎn),并再次提交所有的原語。它是最有用的調(diào)試?yán)L圖。

CCNodeColor

繪制一個(gè)方形,用固體顏色填充。

CCNodeGradient

繪制一個(gè)填充漸變的矩形。您可以指定開始和結(jié)束顏色和梯度的方向。

CCrenderTexure

創(chuàng)建一個(gè)包含繪制在渲染紋理上的節(jié)點(diǎn)的紋理。創(chuàng)建的紋理可以作為sprite的輸入或者圖像存入磁盤。常用于創(chuàng)建一個(gè)場景的截圖或一個(gè)場景的節(jié)點(diǎn)樹的一個(gè)分支


CCSprite

繪制一個(gè)圖片在屏幕上。圖像可以繪制的顏色(調(diào)色)、傾斜、半透明等效果。CCSprite是使用最頻繁的一個(gè)node。理論上你可以創(chuàng)建幾乎任何游戲完全的精靈,雖然其他節(jié)點(diǎn)可能更有效(ccnodecolor,ccnodegradient)或維護(hù)(cclabelttf,cclabelbmfont)視情況而定。

CCSprite9Slice

本質(zhì)上一個(gè)sprite將他的圖片劃分為9個(gè)區(qū)域,因此取該名稱。當(dāng)中心去不延生至內(nèi)容的尺寸時(shí),邊界區(qū)域繪制不會擴(kuò)大。用于創(chuàng)建用戶界面框架,需要能夠與無框架的邊界變得模糊或混淆的內(nèi)容延伸。CCSprite9Slice通過用戶界面例如CCButton這樣的node內(nèi)部使用。

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創(chuàng)建了多樣的虛擬效果,每一個(gè)都可以和另一個(gè)關(guān)聯(lián)組合起來。

CCClippingNode

剪切node能夠使用任何模板,因此只有模板node的區(qū)域是能繪制的或者效果翻轉(zhuǎn)。

CCMotionStreak

用于繪制一條逐漸淡出的線??梢宰鳛橐粋€(gè)觸摸和拖動指示器。

CCParticleSystem

一個(gè)顆粒發(fā)射器能夠創(chuàng)建顆粒流。顆粒如同縮小版的sprites,但是繪制的速度要快于相同數(shù)量的sprits.你可以修改的顆粒發(fā)射器的參數(shù)來改變動畫效果。你不能或者無法修改私有的顆粒在運(yùn)行狀態(tài)下,他們也不能擁有物理的身體。

CCProgressNode

一個(gè)spirte能夠動態(tài)的展示給定的完成百分比。sprite能夠逐步的填滿和展示另一個(gè)sprite。這個(gè)可以用來載入bar和計(jì)時(shí)器的冷卻。

Label Nodes?

cocos2D 能繪制兩個(gè)類型的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.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容