• starling 中的 EventDispatcher 和 Flash中原生的 EventDispatcher


    starling 比较早之前就有开始解了,但只到最近参与一个用starling 做为框架的手游项目才真正做为一程来使用它。 项目也是刚开始搭建,在这做些笔记。

     在写一个管理类时, 遇到 starling.events.EventDispatcher 和 flash.events.EventDispatcher, 这两者有什么区别呢,查了下手册

    Package starling.events
    Class public class EventDispatcher
    Inheritance EventDispatcher Inheritance Object
    Subclasses DelayedCall, DisplayObject, Starling, Tween

    The EventDispatcher class is the base class for all classes that dispatch events. This is the Starling version of the Flash class with the same name.

    The event mechanism is a key feature of Starling's architecture. Objects can communicate with each other through events. Compared the the Flash event system, Starling's event system was simplified. The main difference is that Starling events have no "Capture" phase. They are simply dispatched at the target and may optionally bubble up. They cannot move in the opposite direction.

    As in the conventional Flash classes, display objects inherit from EventDispatcher and can thus dispatch events. Beware, though, that the Starling event classes are not compatible with Flash events: Starling display objects dispatch Starling events, which will bubble along Starling display objects - but they cannot dispatch Flash events or bubble along Flash display objects.

     这可以看出, starling中的eventDispatcher 跟原生的是两个完全不同的接口不同的类, 相比较而言,更简洁, 没有原生的捕获阶段,目标阶段,冒泡阶段。 可以自设事件是否需要冒泡,但这是单向不可逆的。

    dispatchEventWith(type:String, bubbles:Boolean = false, data:Object = null):void
    Dispatches an event with the given parameters to all objects that have registered listeners for the given type.

    由于starling 内部的显示对象都是继承 starling.events.EventDispatcher 所以 建议所有渲染相关的事件都用 starling.events

    其它自定义的游戏逻辑,建议用原生的 flash.events 便于扩展。

  • 相关阅读:
    [转]shell getopts用法
    [转]KVM虚拟化原理探究
    [转]存储相关的一些概念解释
    [转]绑定设备到驱动
    [转] SCSI, FC, ISCSI协议
    [转译]zoned storage device
    CORS jsonp
    orange---openresty.---authorization,-129.0.1.227,jwt
    vue
    hive sqoop,sqoop-hive import data
  • 原文地址:https://www.cnblogs.com/bobolive/p/3166501.html
Copyright © 2020-2023  润新知