Class cc.Layer

Class Summary
Constructor Attributes Constructor Name and Description
 
cc.Layer is a subclass of cc.Node that implements the TouchEventsDelegate protocol.

Method Summary

Class Detail

cc.Layer()
cc.Layer is a subclass of cc.Node that implements the TouchEventsDelegate protocol.
All features from cc.Node are valid, plus the following new features:
It can receive iPhone Touches
It can receive Accelerometer input

Method Detail

  • <static> {cc.Layer|Null} cc.Layer.create()
    creates a layer
    // Example
    var myLayer = cc.Layer.create();
    //Yes! it's that simple
    Returns:
    {cc.Layer|Null}
  • {Number} getTouchMode()
    returns the touch mode.
    Returns:
    {Number}
  • {Number} getTouchPriority()
    returns the priority of the touch event handler
    Returns:
    {Number}
  • {Boolean} init()
    Returns:
    {Boolean}
  • {Boolean} isAccelerometerEnabled()
    whether or not it will receive Accelerometer events
    You can enable / disable accelerometer events with this property.
    Returns:
    {Boolean}
  • {Boolean} isKeyboardEnabled()
    whether or not it will receive keyboard events
    You can enable / disable accelerometer events with this property.
    it's new in cocos2d-x
    Returns:
    {Boolean}
  • {Boolean} isTouchEnabled()
    whether or not it will receive Touch events.
    You can enable / disable touch events with this property.
    Only the touches of this node will be affected. This "method" is not propagated to it's children.
    Returns:
    {Boolean}
  • onEnter()
    This is run when ever a layer just become visible
  • onEnterTransitionDidFinish()
    this is called when ever a layer is a child of a scene that just finished a transition
  • onExit()
  • onKeyDown(keyCode)
    Call back when a key is pressed down
    // example
    if(keyCode == cc.KEY.w){}
    Parameters:
    {Number} keyCode
  • onKeyUp(keyCode)
    Call back when a key is released
    // example
    if(keyCode == cc.KEY.w){}
    Parameters:
    {Number} keyCode
  • {Boolean} onMouseDown(mouse)

    called when the "mouseDown" event is received.
    Return YES to avoid propagating the event to other delegates.

    Parameters:
    {cc.Mouse} mouse
    Returns:
    {Boolean}
  • {Boolean} onMouseDragged(mouse)

    called when the "mouseDragged" event is received.
    Return YES to avoid propagating the event to other delegates.

    Parameters:
    {cc.Mouse} mouse
    Returns:
    {Boolean}
  • {Boolean} onMouseEntered(mouse)

    called when the "mouseEntered" event is received.
    Return YES to avoid propagating the event to other delegates.

    Parameters:
    {cc.Mouse} mouse
    Returns:
    {Boolean}
  • {Boolean} onMouseExited(mouse)

    called when the "mouseExited" event is received.
    Return YES to avoid propagating the event to other delegates.

    Parameters:
    {cc.Mouse} mouse
    Returns:
    {Boolean}
  • {Boolean} onMouseMoved(mouse)

    called when the "mouseMoved" event is received.
    Return YES to avoid propagating the event to other delegates.

    Parameters:
    {cc.Mouse} mouse
    Returns:
    {Boolean}
  • {Boolean} onMouseUp(mouse)

    called when the "mouseUp" event is received.
    Return YES to avoid propagating the event to other delegates.

    Parameters:
    {cc.Mouse} mouse
    Returns:
    {Boolean}
  • {Boolean} onOtherMouseDown(mouse)

    called when the "otherMouseDown" event is received.
    Return YES to avoid propagating the event to other delegates.

    Parameters:
    {cc.Mouse} mouse
    Returns:
    {Boolean}
  • {Boolean} onOtherMouseDragged(mouse)

    called when the "otherMouseDragged" event is received.
    Return YES to avoid propagating the event to other delegates.

    Parameters:
    {cc.Mouse} mouse
    Returns:
    {Boolean}
  • {Boolean} onOtherMouseUp(mouse)

    called when the "otherMouseUp" event is received.
    Return YES to avoid propagating the event to other delegates.

    Parameters:
    {cc.Mouse} mouse
    Returns:
    {Boolean}
  • {Boolean} onRightMouseDown(mouse)

    called when the "rightMouseDown" event is received.
    Return YES to avoid propagating the event to other delegates.

    Parameters:
    {cc.Mouse} mouse
    Returns:
    {Boolean}
  • {Boolean} onRightMouseDragged(mouse)

    called when the "rightMouseDragged" event is received.
    Return YES to avoid propagating the event to other delegates.

    Parameters:
    {cc.Mouse} mouse
    Returns:
    {Boolean}
  • {Boolean} onRightMouseUp(mouse)

    called when the "rightMouseUp" event is received.
    Return YES to avoid propagating the event to other delegates.

    Parameters:
    {cc.Mouse} mouse
    Returns:
    {Boolean}
  • {Boolean} onScrollWheel(mouse)

    called when the "scrollWheel" event is received.
    Return YES to avoid propagating the event to other delegates.

    Parameters:
    {cc.Mouse} mouse
    Returns:
    {Boolean}
  • {Boolean} onTouchBegan(touch, event)
    default implements are used to call script callback if exist
    you must override these touch functions if you wish to utilize them
    Parameters:
    {cc.Touch} touch
    {event} event
    Returns:
    {Boolean}
  • onTouchCancelled(touch, event)
    Parameters:
    {cc.Touch} touch
    {event} event
  • onTouchEnded(touch, event)
    callback when a touch event finished
    Parameters:
    {cc.Touch} touch
    {event} event
  • onTouchesBegan(touches, event)
    Touches is the same as onTouchBegan, except this one can handle multi-touch
    Parameters:
    {array} touches
    {event} event
  • onTouchesCancelled(touches, event)
    Parameters:
    {array} touches
    event
  • onTouchesEnded(touches, event)
    Parameters:
    {array} touches
    {event} event
  • onTouchesMoved(touches, event)
    Parameters:
    {array} touches
    {event} event
  • onTouchMoved(touch, event)
    callback when a touch event moved
    Parameters:
    {cc.Touch} touch
    {event} event
  • registerWithTouchDispatcher()
    If isTouchEnabled, this method is called onEnter.
  • setAccelerometerEnabled(enabled)
    isAccelerometerEnabled setter
    Parameters:
    {Boolean} enabled
  • setAccelerometerInterval(interval)
    accelerometerInterval setter
    Parameters:
    {Number} interval
  • setKeyboardEnabled(enabled)
    Enable Keyboard interaction
    Parameters:
    {Boolean} enabled
  • setKeypadEnabled(enable)
    use for jsb
    Parameters:
    enable
  • setTouchEnabled(enabled, swallow)
    Enable touch events
    Parameters:
    {Boolean} enabled
    {Boolean} swallow Optional, Default: true
    if the event listener will swallow touch after been triggered
  • setTouchMode(mode)
    Sets the touch mode.
    Parameters:
    {Number} mode
  • setTouchPriority(priority)
    Sets the touch event handler priority. Default is 0.
    Parameters:
    {Number} priority