1 Star 0 Fork 25

踩菇凉的小蘑菇 / p1

forked from Fengziii / p1 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

框架说明

Build Status

交流QQ群:65384669

目录

  1. 框架定位
  2. 框架初始化流程
  3. 模块进入流程
  4. 模块退出流程
  5. 君子约定
  6. Egret相关
  7. 待办事宜
  8. 代码示例
  9. Lisence

框架定位:

「让做游戏变简单!」

本框架定位于简化游戏流程,提高团队开发效率,目前提供了管理模块间关系,处理底层事务,及松散的工具集合,使开发者专注于游戏本身的逻辑。

框架初始化流程:

模块进入流程:

模块退出流程:

君子约定:

  1. 类文件及类名统一首字母大写,文件名不宜过长,尽量在单个文件内写一个类,只有当前类引用的类和枚举可以写在同一文件内
  2. 资源文件统一小写
  3. 给接口名称加上大写字母I做为前缀,表示该类型为接口类型
  4. 成员变量以m_开头
  5. 私有静态变量以s_开头
  6. 临时变量以t_开头
  7. 常量及枚举项所有单词大写

Egret相关:

  1. 通过FrameEventCenter替代帧循环监听
  2. 通过TimerManager替代new Timer
  3. 尽量用序列帧代替透明度渐变及遮罩实现的动画
  4. 少用get、set语法糖,如需使用子类在调用父类的get、set需采用egret自身封装的方法
  5. 图片资源尽量合并为大图
  6. 文本文件采用zip压缩
  7. 常用UI面板关闭时尽量缓存
  8. 减少频繁的实例化,请使用对象池
  9. 在适当的时候销毁实例化对象及Resource加载的资源
  10. 根据变量的使用频率决定它是否为临时变量
  11. 注意UI与逻辑分离,逻辑与数据分离,
  12. 谨慎的选择需要使用的容器类型,显示类尽量从Component和EUIComponent继承

待办事宜:

  • 为进行中
  • 为未开始

  • 修复框架中的BUG
  • 常用UI组件的开发

代码示例:

Main.ts

class Main extends egret.DisplayObjectContainer {



    public constructor() {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
    }

    private onAddToStage(event: egret.Event) {

        egret.lifecycle.addLifecycleListener((context) => {
            // custom lifecycle plugin

            context.onUpdate = () => {

            }
        })

        egret.lifecycle.onPause = () => {
            egret.ticker.pause();
        }

        egret.lifecycle.onResume = () => {
            egret.ticker.resume();
        }
        //inject the custom material parser
        //注入自定义的素材解析器
        let assetAdapter = new AssetAdapter();
        egret.registerImplementation("eui.IAssetAdapter", assetAdapter);
        egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());
        core.Core.run(this.stage);
        core.LayerCenter.getInstance().addLayer(LayerEnum.BG, new core.Layer());
        core.LayerCenter.getInstance().addLayer(LayerEnum.UI, new core.EUILayer());
        core.LayerCenter.getInstance().addLayer(LayerEnum.POPUP, new core.Layer());
        core.LayerCenter.getInstance().addLayer(LayerEnum.LOADING, new core.EUILayer());
        core.LayerCenter.getInstance().addLayer(LayerEnum.TOP, new core.Layer());
        this.runGame().catch(e => {
            console.log(e);
        });
    }

    private async runGame() {
        core.LoadingManager.setCurLoading(LoadingUI).show();
        await this.loadResource()
        await platform.login();
        const userInfo = await platform.getUserInfo();
        console.log(userInfo);
        core.ResUtils.loadGroups(["preload"], this.onResourceProgress, this.onResourceLoadError, this.onResourceLoadComplete, this);
    }

    private async loadResource() {
        try {
            await RES.loadConfig("resource/default.res.json", "resource/");
            await this.loadTheme();
        }
        catch (e) {
            console.error(e);
        }
    }

    private loadTheme() {
        return new Promise((resolve, reject) => {
            // load skin theme configuration file, you can manually modify the file. And replace the default skin.
            //加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。
            let theme = new eui.Theme("resource/default.thm.json", this.stage);
            theme.addEventListener(eui.UIEvent.COMPLETE, () => {
                resolve();
            }, this);

        })
    }

   
    /**
     * 资源组加载进度
     * @param  {core.GroupData} data
     */
    private onResourceProgress(data: core.GroupData): void {
        egret.log(`当前加载进度:${data.curGroup} ${data.curGroupLoaded}/${data.curGroupTotal}`);
        core.LoadingManager.getLoading(LoadingUI).setProgress(data);
    }
    
    /**
     * 资源组加载出错
     * @param  {core.GroupData} data
     */
    private onResourceLoadError(data: core.GroupData): void {
        //TODO
        egret.log("Group:" + data.curGroup + " has failed to load");
    }
    /**
     * preload资源组加载完成
     * @param  {core.GroupData} data
     */
    private onResourceLoadComplete(data: core.GroupData): void {
        if (data.curGroup == 'preload') {
            egret.log("Group:" + data.curGroup + " load complete");
            core.LoadingManager.getLoading(LoadingUI).hide();
            core.Config.init(RES.getRes('config_zip'));
            this.initModule();
            UIManager.instance.openModule(ModuleEnum.LOGIN);
        }
    }

    private initModule(): void {
        new GameModule();
        new LoginModule();
        new MainModule();
    }
}

LoginModule.ts

class LoginModule extends core.Module {
	public constructor() {
		super(ModuleEnum.LOGIN);
	}
	private m_pLoginUI: LoginUI;

	/**
	* 获取loading
	*/
	protected getLoading(): core.ILoadingUI {
		return core.LoadingManager.getLoading(MainLoadingUI);
	}
	/**
	 * 预加载资源组
	 */
	protected getLoadGroup(data?: core.ModuleEventData): string[] {
		return ['soundUI', 'animUI'];
	}
	/**
	 * 显示
	 */
	protected show(data?: any): void {
		if (!this.m_pLoginUI) {
			let loginUI: LoginUI = new LoginUI();
			this.m_pLoginUI = loginUI;
		}
		core.LayerCenter.getInstance().getLayer(LayerEnum.UI).addChild(this.m_pLoginUI);
	}
	/**
	 * 隐藏
	 */
	protected hide(): void {
		if (this.m_pLoginUI && this.m_pLoginUI.parent) {
			this.m_pLoginUI.parent.removeChild(this.m_pLoginUI);
		}
		this.m_pLoginUI = null;
	}

	protected release(): void {
		super.release();
	}
}

Lisence

MIT

MIT License Copyright (c) 2017-2027 yuxuefeng Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个基于egret引擎的游戏框架 展开 收起
TypeScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/2283960715/p1.git
git@gitee.com:2283960715/p1.git
2283960715
p1
p1
master

搜索帮助