Git Product home page Git Product logo

cocos-game-framework's Introduction

cocos 轻量级游戏框架

996.icu blog

说明

  • 以个人实践为主,有些方案并非是最佳实践。
  • 适用于轻量级游戏,单一场景,界面使用 prefab 进行管理。
  • 适用于新手,仅包含一些基础的游戏模块。
  • 为什么需要游戏框架?https://www.yuque.com/fengyong/game-develop-road/dmuel4

使用方法

  • 拷贝 release 页面中的相应文件到自己的项目中。
    • fy-*.d.ts,是框架声明文件,需要拷贝到 assets 目录外。
    • fy-*.dev.js,是框架文件,需要拷贝到 assets 目录下,并设置为插件脚本。
    • fy-*.min.js,是框架压缩文件,用于代替 dev.js 文件。不推荐使用,因为我已不再开发游戏,缺少大量的实际测试,框架不可避免会有一些 bug,使用压缩文件不易 debug。
  • 下载完整项目,执行 npm install && npm run build 命令,拷贝 dist 目录下的相应文件到项目中。
  • 模块实现参考。

项目

工具依赖

  • typescript
  • eslint
  • prettier
  • jest
  • rollup

目录

  • src/ 框架源码
  • dist/ 框架打包内容
  • types/ 框架自定义声明文件
  • .vscode/ vscode 配置
  • .gitignore git 配置
  • package.json 依赖配置
  • package-lock.json
  • rollup.config.js rollup 配置
  • tsconfig.json typescript 配置
  • .eslintrc.json eslint 配置
  • .prettierrc prettier 配置
  • .prettierignore
  • jest.config.js jest 配置

设计规范

  • 【去依赖】框架除依赖 cocos creator 之外,不依赖其他外部库。
  • 【独立化】减少框架内模块的相互依赖。
  • 【扁平化】文件即作为一个模块。模块中 export 的全部内容均处于全局 fy 下。针对部分模块不适合放在全局下的,可以额外添加 1 层。

命名规范

  • 命名规范参考 .eslintrc.json 文件
  • 方法名使用动宾结构 do_something 完整描述。
    动词 含义
    get 获取某个值。
    set 设置某个值。一般没有返回值。
    change 修改某个值。
    to 转义某个值。
    do 执行某个逻辑。
    try 尝试执行某逻辑,一般后面还需要一个动词。一般返回 boolean 表示是否执行成功。
    is 判断某个逻辑。不要使用 are 来做区分。
    load 载入某个资源,一般用于引擎资源载入。
    init 初始化某个模块。
    call 调用原生。
    log 生成 log 信息。
    random 获取某个随机值。
    ... ...
  • 一般不要使用缩写。部分缩写含义如下:
    缩写 完整含义
    ins instance,实例。
    wp world position,世界坐标。
    lp local position,本地坐标。
    ... ...
  • 一般不要使用前缀后缀。部分前后缀含义如下:
    前缀后缀 含义
    config 配置信息。
    event 事件名。
    meta 配置表脚本。
    panel 界面脚本。
    params 参数,一般为复数。
    ... ...

git commit message 规范

  • 参考资料:http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html
  • TODO:未来会增加自动 change log。
  • 7 个标识:
    标识 含义
    feat 新功能。
    fix 修补 bug。
    docs 文档。
    style 格式。不影响代码运行的变动。
    refactor 重构。即不是新增功能,也不是修改 bug 的代码变动。
    test 增加测试。
    chore 构建过程或辅助工具的变动。

代码规范

  • 代码次序为:
    1. 依赖:import/export/cc._decorator
    2. 特殊数据:C-常量配置数据/EVENT-事件
    3. 类型定义:enum/interface/type/class
    4. 常量,变量,方法
  • 使用 undefined 而不是 null。二者几乎没差别,但 null 一般表示此处不应该有值,undefined 一般表示此处有应该有值但未定义。
  • 使用 export 而不是 export default。
  • 使用 export namespace(模块) 而不是 namespace(命名空间)。
  • 优先使用 private 而不是 public。
  • 一般不要使用 _ 作为命名的开头。例外情况是:这个方法需要被导出,但并不希望被使用。
  • 使用箭头函数而不是 function。
  • 将方法参数中,object 或 function 类型的参数,置于最后。
  • 优先使用 implements(组合) 而不是 extends(继承)。
  • 使用「双引号」或「反引号」而不是单引号。
  • 使用「字符串字面量类型」或「字符串枚举」而不是「数字枚举」。
  • 使用 forEach 或者其他高阶方法遍历而不是 for 循环。(for 循环的性能最高,在大数组遍历时可以使用)(高阶方法参考:https://www.yuque.com/fengyong/game-develop-road/gwv8xo )。还应该避免在 for 循环时添加 break 和 return 逻辑,这样做会影响循环的语义性。

cocos-game-framework's People

Contributors

doooreyn avatar fkworld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cocos-game-framework's Issues

声音在loop设定为true时在打包为android后无法播放

bug表现:bgm(声音&loop为true)在打包为android后无法播放

bug原因:cc.audioEngine.getState方法,在web平台和android平台下的返回值不同。
在web平台中:
cc.audioEngine.getState(undefined)===-1,其中-1代表cc.audioEngine.AudioState.ERROR
在android平台中:
cc.audioEngine.getState(undefined)===undefined

bug临时处理方案:
针对undefined的这一特殊返回值进行处理,与cc.audioEngine.AudioState.ERROR的处理逻辑相同。

export arrow function has no name

这是一个ts语言的相关bug,相关的issue也很多,但都还没有解决。

表现为:

const a = () => {};
export const b = () => {};
console.log(a.name === "a", b.name === "b", b.name === "");
// true false true

可以看到,如果是普通的箭头函数,则可以正确获取函数名;如果是被导出的箭头函数,则无法正确获取函数名。

因此,在此bug未被官方解决之前,建议使用export function来定义函数。同时,在tsconfig中添加noImplicitThis配置来防止this的滥用。

FVersion模块的bug

是由FVersion.version并未直接赋值引发的,表现为在使用dev_console或者dev_console_namespace,就会报错:
load script [……] failed : TypeError: Cannot read property 'has_state' of null

Roadmap: 2020.6

  • 使用typedoc生成项目文档
  • 添加项目的wiki
  • prettier配置化,添加忽略大文件的功能 #47
  • rollup多文件输出 #48
  • 修改csv的生成,不再生成json文件,直接生成ts文件 #45
  • 修改meta的配置,只传入一张csv表 #51
  • 将示例项目中的TText,TColor,TChild的实现迁移到框架中 #52
  • bug:在没有载入meta数据时获取,会导致比较大的异常 #51
  • 使用export function代替export arrow function #49 #46
  • 新增panel模块的refresh方法
  • 新增eslint规范编码 #53
  • 生成单个的d.ts文件 #54

G.run_by_interval_frame抛出resolve的时机错误

目前会在最后1次执行前抛出resolve

改为

        return new Promise(res => {
            let count = (all_count - 1) * interval  // 执行总帧数
            let frame_index = 0     // 帧index
            let f_index = 0         // 函数执行index
            ccc.schedule(() => {
                if (frame_index % interval === 0) {
                    f(f_index)
                    f_index += 1
                }
                frame_index += 1
                frame_index > count && res()
            }, 0, count)
        })

Roadmap 2019

最近的工作主要是接SDK,游戏制作水平没有什么进步。抽空写一下框架中需要更改的部分:

  1. 支持到 cocos creator 2.1.3,未来会紧随着最新版本。
  2. 以 panel 系统为原型,完善配置(值配置+类型配置)的解决方案,作为示例。
  3. 以 panel-ui 系统为原型,完善使用状态模式管理简单的 ui 组件动画,作为示例。
  4. 新增 meta 系统,即数值系统,将配置好的数值表转化为游戏内可查询的数据模块。
  5. 新增 event 系统,即事件系统。
  6. 固定 api,出 1.0 的 release 版本。

简化 sound 配置信息

应该简化 sound 的配置信息,使其仅保留文件路径。
需要区分开来音乐和音效。
需要对声音的大小进行外部调整处理,在游戏内部以 1 的大小进行播放。

FPanel.open的后面的参数怎么传?

await FPanel.open(PanelLoading, {})
await FPanel.close(PanelLoading, {})
await FPanel.open(PanelGame, {})
看代码应该是传入一些动画效果,但是这个动画应该怎么写?
type ParamsPanelOpen = Parameters<T["prototype"]["on_open"]>[0] extends undefined ? {} : Parameters<T["prototype"]["on_open"]>[0];
这个东西看的有点懵,不知道应该怎么做?望大神解答

重大错误,Function-name属性导致构建后代码不可用

错误表现:
Function-name属性在构建后不可用。
可能的原因:
cocos-creator编辑器没有完善Function-name属性的es5实现,导致了在编辑器预览是可用,构建后不可用。
修复方案一:
我搜索了源码,除了MPanel中使用较多,其余使用地方均为在log中,影响不大。
建议在所有的子panel中手动实现一个static fname属性,并且将MPanel.ts中所有的panel.name更换为panel.fname。即可修复此bug。
修复方案二:
我会在近期更新一个MPanel基于非name的实现。
修复方案三:
等待cocos-creator官方修复,已经提了issue:cocos/cocos-engine#4358

meta 数据应该存在空字符串

现在对 meta 数据的处理为,如果为空,则赋值为此行的 id。
这种赋值方式是不恰当的,因为确实存在空字符串为其配置信息。

bug:mpanel现有逻辑导致界面在打开2次时出现异常

现有的mpanel逻辑导致:
在界面第1次打开时,调用2次打开逻辑导致界面打开2次的bug。
出现bug的原因是:
第1次进入了loadRes的异步过程,第2次在异步过程未结束时也进入了一个loadRes的异步过程。

从哪里获取到 cocos2d-js-min.js

请问从哪获取到的 cocos2d-js-min.js?
我想在自己的项目里使用并保持持续更新应该怎么做?

你的cocos2d-js-min.js是不是就是这里的cocos2d-js-for-preview.js?

panel 载入流程错误

在游戏启动时,如果打开了页面但是此页面还未载入成功,则会导致打开失败。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.