The labor results of the staff, when reproduced please be sure to indicate the source : http://blog.csdn.net/haomengzhu/article/details/30474393
Scene: Scenesafter knowing the director, let's look at Scene, a game component that is closely related to it. through previous studies, we have learned about the scene and its position in Process control.
in Cocos2d-x, scene defines a scenario. A scene is simply a container of layers. Includes all the game elements that need to be displayed. so, compared to other game elements, Scene does not provide any special features, it is a very simple class. In addition to being a container for layers, the scene has aThe effect is process control. using Director::replacescene and other methods, we can make the game switch freely in different scenes.
during the game development process. When we need to complete a scene. Creates a subclass of the Scene and implements the functionality we need in the subclass. For example, we can load the game resources in the initialization method of the subclass, adding layers to the scene. Start music playback, and so on. At the same time, the scene may also need a certain transition cohesion effect, otherwise, the scene of the switch will appear very abrupt. Cocos2d-x offers a lot of gorgeous scene switching effects. such as page flipping, wave, fade in and so on. These effects are implemented by the Transitionscene series effect classes derived from Scene.
Transitionscene. This scene is used to switch between two scene. Make a scene of transition changes in the middle. The interface design is very clear and simple.
header file in Cocos\2d\cctransition.h; of course, you can also imitate the cocos2d-x built-in scene switch effect code, to write their own special effects.
Layer: Layers the layer defines a level.
Like Scene, the layer also plays the role of a container. However, unlike the scenario, the layer usually includes a direct presentation of the current screen details on: settings Span style= "font-family:kaiti_gb2312; font-size:18px; Background-color:inherit "> The action of the game elements and so on.
this shows. Most of the coding time for game development is spent on the creation layer.
Typically, objects in a layer function similarly. The coupling is tighter, and the logic code associated with the game content in the layer is also written in the layer.
After organizing the layers, it is only necessary to add the layers to the scene in order to be able to show them.
To add layers to the scene, we can use the AddChild method.
The AddChild method has three definitions in common, as seen in detail below:
void AddChild (node* child); Adds a child to the container with Z-order as 0.void AddChild (node* child, int localzorder); void AddChild (node* child, I NT Localzorder, int tag);
the child participant is the node that will be joined. For a scenario, the node that we usually join is the layer.
The layer that is added first is placed below the layer to which it is added. Suppose you want to specify priorities for them. The ability to use different Localzorder values, Localzorder represents the order of the elements under the node. The larger the value, the higher the order of the display .
The default value for Localzorder is 0.
tag is the identification number of the element, assuming that the tag value is set for the child node, it can be found in its parent node using the tag value . it out.
Here we can choose the method we need to add layers to the scene.
In the previous article mentioned in the composition of the small three game scene, find small three game scene roughly by the background layer (Backgroundlayer), the action layer (actionlayer), Touch Layer (Touchlayer), and menu layer (menulayer). If these layers are finished, the last thing we need to do is add them to the scene in the Init method of the game scenario:
This->addchild (backgroundlayer, 0); This->addchild (Actionlayer); This->addchild (touchLayer,200); This->addchild (Menulayer, 300);
A very important feature of Layer is the ability to accept user input events. Includes touch, accelerometer, keyboard input, and more.
In the Cocos2d-x 3.0 version number, the layer is associated with the user input event as seen in the table.
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvagfvbwvuz3podq==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">
and in the 3.0 version number. Adopted the mechanism of event distribution:(1) When used, create an event listener first. Event listeners include the following:
Touch Events (Eventlistenertouch)
Keyboard response Events (Eventlistenerkeyboard)
Speeding up Logging events (eventlisteneracceleration)
Mouse corresponding event (eventlistenermouse)
Define your own events (Eventlistenercustom)
(2) The above event listener is unified by _eventdispatcher to manage. Its work requires three components:
Event Dispatcher Eventdispatcher
Event Type Eventtouch, Eventkeyboard, etc.
Event Listener Eventlistenertouch, Eventlistenerkeyboard, etc.
(3) The listener implements various triggering logic, distributes the event type at the appropriate time by the event dispatcher, and then invokes the listener of the corresponding type
Shimen Main Friendship tips:learned all the game components. You'll be able to build a game with the building blocks 、、、
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
14, COCOS2DX 3.0 Three, find a little game development scene and Layer: Game Dream