# PhaserMobileLayout **Repository Path**: addedme/PhaserMobileLayout ## Basic Information - **Project Name**: PhaserMobileLayout - **Description**: 用YAML配置的方式在移动端实现快速布局的框架 - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2018-07-26 - **Last Updated**: 2024-11-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # PhaserMobileLayout 用YAML配置的方式在移动端实现快速布局的框架 ## TODO - [x] 去掉copy、ref配置的方式,改用template节点复用配置,template的type属性配置Phaser对象类型 ## 特点 - 配置文件布局 - 移动端全屏(自动适应),只需要按照原型设计的分辨率配置布局坐标位置 - 简单,比写代码布局简单,不容易出错 ## 依赖库 - js-yaml (parse YAML text) - lodash (make js easy) ## 使用说明 - 写YAML布局配置文件 - 载入YAML布局配置文件 ```javascript // at previous game state this.game.load.text("MyScene", "assets/layout/MyScene.yaml"); ``` - 继承 **ConfigLayout** 类 e.g. ```javascript var MySceneControl = function () { ConfigLayout.call(this); } MySceneControl.prototype = _.create(ConfigLayout.prototype, { "constructor": MySceneControl, "_super": ConfigLayout.prototype, init: function () { // load a config file this.addLayoutFile("MyScene"); this._super.init(); }, preload: function () { this._super.preload(); }, create: function () { this._super.create(); // TODO: add control for display things }, }); ``` - 获取Phaser显示对象 ```javascript create: function () { this._super.create(); // get background sprite by config name attr var bgSprite = this.get("bg"); // var bgSprite = this.get("背景"); // TODO: add control for display things }, ``` ## 建议 三层分离:显示(view)、控制(control)、业务(service) 1. 使用 **ConfigLayout** 作为显示层 2. 继承 **ConfigLayout** 管理操作Phaser对象 3. 继承第2点(control)类,建议用来实现业务 ## 如何配置 参见 [HowToConfig.md](HowToConfig.md) ## Public License [WTFPL](http://www.wtfpl.net/)