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

  • 相关阅读:
    Xcode界面切换动画效果
    Objective—C中的排序及Compare陷阱
    串行口应用
    在windows上搭建C语言开发环境——借助eclipse和MinGW
    Leetcode--Two Sum
    C++语言笔记系列之十六——赋值兼容规则&多继承的二义性
    在Powerdesigner中创建概念数据模型
    数据模型
    数据描述的三个领域
    开启PowerDesigner15工具栏上的被禁用掉的图标
  • 原文地址:https://www.cnblogs.com/bobolive/p/3166501.html
Copyright © 2011-2022 走看看