Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EventListener


The base class of event listener.
If you need custom listener which with different callback, you need to inherit this class.
For instance, you could refer to EventListenerAcceleration, EventListenerKeyboard,
EventListenerTouchOneByOne, EventListenerCustom.


封装用户的事件处理逻辑。
注意:这是一个抽象类,开发者不应该直接实例化这个类,请参考 create

Hierarchy

Index

Constructors

constructor

  • newEventListener(type: number, listenerID: string, callback: function | null): EventListener

Properties

Private _fixedPriority

_fixedPriority: number = 0

Private _isEnabled

_isEnabled: boolean = true

Private _listenerID

_listenerID: string

Private _node

_node: any = null

Protected onEvent

onEvent: function | null

Private _paused

_paused: boolean = true

Optional _previousIn

_previousIn: undefined | false | true = false

Private _registered

_registered: boolean = false

_target

_target: any = null

Private _type

_type: number

mask

mask: IListenerMask | null = null

owner

owner: Object | null = null

Static ACCELERATION

ACCELERATION: number = 6

加速器事件监听器类型

Static CUSTOM

CUSTOM: number = 8

自定义事件监听器类型

Static KEYBOARD

KEYBOARD: number = 3

键盘事件监听器类型

Static MOUSE

MOUSE: number = 4

鼠标事件监听器类型

Static TOUCH_ALL_AT_ONCE

TOUCH_ALL_AT_ONCE: number = 2

触摸事件监听器类型,触点会被一次性全部派发

Static TOUCH_ONE_BY_ONE

TOUCH_ONE_BY_ONE: number = 1

触摸事件监听器类型,触点会一个一个得分开被派发

Static UNKNOWN

UNKNOWN: number = 0

未知的事件监听器类型

Accessors

onEvent

  • get onEvent(): null | function

Methods

getFixedPriority

  • _getFixedPriority(): number

getListenerID

  • _getListenerID(): string

getSceneGraphPriority

  • _getSceneGraphPriority(): any

getType

  • _getType(): number

isPaused

  • _isPaused(): boolean

Private isRegistered

  • _isRegistered(): boolean

setFixedPriority

  • setFixedPriority(fixedPriority: number): void
  • 设置此侦听器的固定优先级。
    注意:此方法仅用于“固定优先级侦听器”,
    它需要访问非零值。 0保留给场景图优先级侦听器。

    Parameters

    • fixedPriority: number

    Returns void

setPaused

  • setPaused(paused: boolean): void
  • *为侦听器设置暂停状态
    暂停状态仅用于场景图优先级侦听器。
    EventDispatcher :: resumeAllEventListenersForTarget(node)将暂停状态设置为true
    EventDispatcher :: pauseAllEventListenersForTarget(node)将它设置为false
    注意:

    • 固定优先级侦听器永远不会被暂停。 如果固定优先级不想接收事件,改为调用setEnabled(false)
    • 在“Node”的onEnter和onExit中,监听器的“暂停状态”与该节点关联的*将自动更新。

    Parameters

    • paused: boolean

    Returns void

setRegistered

  • setRegistered(registered: boolean): void

setSceneGraphPriority

  • setSceneGraphPriority(node: any): void

checkAvailable

  • checkAvailable(): boolean

clone

isEnabled

  • isEnabled(): boolean

setEnabled

  • setEnabled(enabled: boolean): void
  • 启用或禁用监听器。
    注意:只有处于“启用”状态的侦听器才能接收事件。
    初始化侦听器时,默认情况下启用它。
    事件侦听器可以在启用且未暂停时接收事件。
    当固定优先级侦听器时,暂停状态始终为false。

    Parameters

    • enabled: boolean

    Returns void

Static create

Object literals

Static ListenerID

ListenerID: object

ACCELERATION

ACCELERATION: string = "__cc_acceleration"

KEYBOARD

KEYBOARD: string = "__cc_keyboard"

MOUSE

MOUSE: string = "__cc_mouse"

TOUCH_ALL_AT_ONCE

TOUCH_ALL_AT_ONCE: string = "__cc_touch_all_at_once"

TOUCH_ONE_BY_ONE

TOUCH_ONE_BY_ONE: string = "__cc_touch_one_by_one"

Generated using TypeDoc