(reproduced) "COCOS2DX 3.x Lua" Registration event function

Source: Internet
Author: User
Tags addchild

Source:

Http://www.2cto.com/kf/201409/338235.html

COOCS2DX Version 3.1.1

Registerscripttouchhandler Registering touch-screen events

Registerscripttaphandler Registering Click events

Registerscripthandler Registration basic events include entry exit events for touch screen layers

Registerscriptkeypadhandler Registering keyboard events

Registerscriptacceleratehandler Registration Acceleration Event

Registerscripttouchhandler (can set single point or multipoint)

functiongamewindow:addlayertoucheventmethod1 ()Local functionontouchevent (EventType, x, y)--log ("EventType =": ToString (EventType))        ifEventType = ="began"  Then            --need to return True            returnOntouchbegan (Touch, event)ElseIfEventType = ="moved"  Thenontouchmoved (Touch, event)ElseIfEventType = ="ended"  Thenontouchended (Touch, event)End    Endconfig.bottomLayer:setTouchEnabled (true) Config.bottomLayer:registerScriptTouchHandler (ontouchevent)End

Registerscripttaphandler Registering Click events

functiongamewindow:addbtn ()LocalBTN = cc. Menuitemimage:create ("White.png","Black.png","Black.png") btn:setposition ( the, the)    Local functionBtnclick () log ("Btnclick")    EndBtn:registerscripttaphandler (Btnclick)Localmenu =cc. Menu:create () config.bottomLayer:addChild (menu) menu:setposition (CC.P (0,0)) Menu:addchild (BTN)End

Registerscripthandler Registering Basic Events

functiongamewindow:addlayertoucheventmethod2 ()--Create a single touch-screen event    LocalListener =cc. Eventlistenertouchonebyone:create ()--registering touch screen start eventsListener:registerscripthandler (Ontouchbegan, CC. Handler.event_touch_began)--registering a touch-screen move eventListener:registerscripthandler (ontouchmoved, CC. handler.event_touch_moved)--registering a touchscreen End EventListener:registerscripthandler (ontouchended, CC. handler.event_touch_ended)--get the event dispatcher for the layer    LocalEventdispatcher =Config.bottomLayer:getEventDispatcher ()--Event Dispatcher registers a node eventeventdispatcher:addeventlistenerwithscenegraphpriority (Listener, Config.bottomlayer)End
 

Register a layer's entry exit event usage

functiongamewindow:addlayerenterandexitevent ()Local functiononnodeevent (EventType)ifEventType = ="Enter"  ThenLog ("Enter")        ElseIfEventType = ="Exit"  ThenLog ("Exit")        End    EndConfig.bottomLayer:registerScriptHandler (onnodeevent)End

Registerscripthandler Registering keyboard events

functioncocoevent.addkeyboardevent ()Local functionkeyboardpressed (KeyCode, event)ifKeyCode = = at  ThenLog (" Left")        ElseIfKeyCode = = -  ThenLog (" Right")        ElseIfKeyCode = = -  ThenLog (" up")        ElseIfKeyCode = = -  ThenLog (" Down")        End        --log ("keycode =": ToString (keycode))        --log ("event =": ToString (event))    End     Local functionkeyboardreleased (KeyCode, event)--log ("keycode =": ToString (keycode))        --log ("event =": ToString (event))    End    LocalListener =cc. Eventlistenerkeyboard:create () Listener:registerscripthandler (keyboardpressed, CC. handler.event_keyboard_pressed) Listener:registerscripthandler (keyboardreleased, CC. handler.event_keyboard_released)LocalEventdispatcher =Config.bottomLayer:getEventDispatcher () eventdispatcher:addeventlistenerwithscenegraphpriority (Listener, Config.bottomlayer)End

(reprinted) "COCOS2DX 3.x Lua" Registration event function in detail

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.