Dahai teaches you how to perform mobile games 5cocoslua first season _ 02 scenario jump and user touch, 2015cocoslua_02

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.