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 便于扩展。

  • 相关阅读:
    什么是JDBC的最佳实践?
    如何将jquery对象转换为js对象?
    JQuery有几种选择器?
    jQuery 库中的 $() 是什么
    JS 中 == 和 === 区别是什么?
    有两张表;请用SQL查询,所有的客户订单日期最新的前五条订单记录?
    根据你以往的经验简单叙述一下MYSQL的优化?
    数据库MySQL分页时用的语句?
    LeetCode231-2的幂(水题,考察是否粗心)
    LeetCode191-位1的个数(题目有问题)
  • 原文地址:https://www.cnblogs.com/bobolive/p/3166501.html
Copyright © 2011-2022 走看看