首页
学习
活动
专区
圈层
工具
发布

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

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

代码语言:javascript
复制
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来处理。

下一篇
举报
领券