zoukankan      html  css  js  c++  java
  • 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 便于扩展。

  • 相关阅读:
    植物 miRNA 研究
    TargetScan 数据库简介
    miRTarBase 数据库简介
    dendrogram 和 barplot 的组合
    多线程基础必要知识点!看了学习多线程事半功倍
    Thread源码剖析
    多线程三分钟就可以入个门了!
    Java集合总结【面试题+脑图】,将知识点一网打尽!
    3分钟搞掂Set集合
    TreeMap就这么简单【源码剖析】
  • 原文地址:https://www.cnblogs.com/bobolive/p/3166501.html
Copyright © 2011-2022 走看看