Dahai teaches you how to perform mobile games 5cocoslua first season _ 02 scenario jump and user touch, 2015cocoslua_02
:
Course address: http://ke.qq.com/cgi-bin/courseDetail? Course_id = 78017
Cocos2d-x live course exchange group: 461039382 (publish videos and materials for each course)
Network Disk Data download: http://pan.baidu.com/s/1dDvZvAp (password to enter the group to have)
Xi's speech in Macao quoted a classic saying: "The best is the best, the power is the best, the power is the best, if the right is lost, it will be abandoned; if the right is lost, it will be hurt. If the right is lost, it will become a long time." If you are a business or partner, or in interpersonal communication, you should cherish your fate and time. Learn to be grateful for your kindness. treat each other with sincerity and meet each other with your heart! Together with the advanced, and with the German, must be good! Feeling: If you have a good heart, you will have a cloud in your life! -- Sharing
This course mainly introduces how to switch the scenario and how to implement user interaction in the game. First, let's look at the main functions in the director class:
1. Director in the game
+ (Director) getinstance
Obtain Singleton
-(Void) runWithScene :( Scene *) scene
Push the scenario object into the stack and activate it (there cannot be any activated scenario at this time, so this method is often used when you just enter the game ).
-(Void) pushScene :( Scene +) scene
Add a new scenario to the stack and activate it.
-(Void) popScene
The current active scenario is out of the stack and the previous scenario is activated.
-(Void) pause
Pause
-(Void) resume
Restore
Next, let's take a look at the basic functions of the Node class: For details, refer to the online storage course.
2. Node
Drawing Node
Parent-child relationship
Anchor
Transform
Attribute
Scheduled tasks
Mark
Action
3. This course describes how to implement Node scheduled tasks.
Local function logic ()
......
End
Node: scheduleUpdateWithPriorityLua (logic, 1)
-------------------------------------------
Note: The execution is performed every 1/60 seconds.
Node must be displayed on the current screen
A scheduled task is executed by ctor in a unified manner within each frame to summarize all game logic. Therefore, do not create sub-threads and errors may occur.
4. We introduced how to handle screen touch events.
-- 1 Define the Event Callback Function
Local function touchBegan (t, e)
Return true
End
Local function touchMoved (t, e)
End
Local function touchEnded (t, e)
Print ("touchEnded ")
End
-- 2. Define the event listening object
Locallistener = cc. EventListenerTouchOneByOne: create ()
Listener: registerScriptHandler (touchBegan, cc. Handler. EVENT_TOUCH_BEGAN)
Listener: registerScriptHandler (touchMoved, cc. Handler. EVENT_TOUCH_MOVED)
Listener: registerScriptHandler (touchEnded, cc. Handler. EVENT_TOUCH_ENDED)
-- 3. Bind the listener to the event source and add it to the event distributor.
Cc. Director: getInstance (): getEventDispatcher ()
: AddEventListenerWithSceneGraphPriority (listener, layer)
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.