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

  • 相关阅读:
    新版vscode配置eslint自动格式化代码
    vue cli4 拿到一个项目后
    windows 网页打不开github网站
    PHP+jQuery-ui拖动浮动层排序并保存到数据库实例
    php+html5兼容手机端的图片选取裁剪上传实例
    PHP+MySQL设计高效发表评论留言功能
    5种PHP生成图片验证码实例
    PHP+jPaginate插件制作无刷新分页实例
    PHP+Mysql实现网站顶和踩投票功能实例
    jQuery+PHP实现购物商城常用的星级评分效果
  • 原文地址:https://www.cnblogs.com/bobolive/p/3166501.html
Copyright © 2011-2022 走看看