- Scenes
- Director
- Layers
- Sprites
Scenes
A scene is more or less an independent piece of the app workflow. Your app can have many scenes, but only one of them is active at a given time.
A cocos2d
Sample Workflow using Scenes |
CCScene
is composed of one or more layers (CCLayer), all of them piled up. Layers give the scene an appearance and behavior; the normal use case is to just make instances of Scene with the layers that you want.There is also a family of
CCScene
classes called transitions (CCTransitionScene
) which allow you to make transitions between two scenes.Since scenes are subclasses of
CCNode
, they can be transformed manually or by using actions.
Director
TheCCDirector
is the component which takes care of going back and forth between scenes. The
CCDirector
is a shared (singleton) object. It knows which scene is currently active, and it handles a stack of scenes. The CCDirector
is the one who will actually change the CCScene
, after a CCLayer
has asked for push, replacement or end of the current scene.Layers
A CCLayer
has a size of the whole drawable area, and knows how to draw itself. It can be semi transparent, allowing to see other layers behind it. Layers are the ones defining appearance and behavior, so most of your programming time will be spent coding CCLayer
subclasses that do what you need.
The CCLayer
is where you define event handlers. Events are propagated to layers until some layer catches the event and accepts it.
Cocos2d provides a library of useful predefined layers such as CCMenu
, CCColorLayer
, CCMultiplexLayer
.
Layers can contain CCSprite
objects, CCLabel
objects and even other CCLayer
objects as children.
Since layers are subclass of CCNode
, they can be transformed manually or by using actions.
Sprites
A cocos2d' sprite is like any other computer sprite. It is a 2D image that can be moved, rotated, scaled, animated, etc.
Sprites (
CCSprite
) can have other sprites as children. When a parent is transformed, all its children are transformed as well.
Since sprites are subclass of
CCNode
, they can be transformed manually or by using actions.
沒有留言:
張貼留言