Cocos2d-js中的简易MVC框架(四)显示层View

来源:互联网 发布:centos设置ip地址 编辑:程序博客网 时间:2024/05/16 18:22

View的功能比较简单,View在MVC结构中负责显示和接收事件。在Cocos2d-JS中Scene和Layer都是View,View只负责显示和接收事件,不负责处理逻辑。在框架中View的实现分为两类,一类是IScene继承自cc.Scene负责场景显示,另一类是IView继承自cc.Layer负责场景上的层显示。IScene和IView的实现如下:

game.IScene = cc.Scene.extend({
    ctor:function () {
        this._super();
    },
    //Use this function to send notification.
    send:function (key, obj) {
        game.Notification.send(key, obj);
    }
});game.IView = cc.Layer.extend({
    ctor:function () {
        this._super();
      return true;
    },
    //Use this function to send notification.
    send:function (key, obj) {
        game.Notification.send(key, obj);
    }
});

    send函数的用途是在View接收到用户的触摸事件或其他事件时向Mediator发送消息,具体处理逻辑由Mediator来处理。

如果你喜欢我的文章就关注我吧:

0 0
原创粉丝点击