npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

keytops-game-framework

v1.0.24

Published

cocos creator game framework library

Readme

keytops-game-framework

keytops-game-framework 是面向 Cocos Creator 项目的游戏开发框架,提供应用生命周期、网络通信、平台能力、存储、计时器、ECS、FSM、任务、埋点、视图、资源和音频等基础设施。这个包定位于框架层,适合需要直接使用底层模块和引擎适配能力的项目,不是精简 facade SDK。

适用场景

  • 使用 Cocos Creator 构建完整游戏项目
  • 需要统一的应用启动、平台接入和模块化基础设施
  • 需要网络、ECS、FSM、埋点、视图和资源管理能力
  • 需要在框架层扩展自定义注入或平台能力

安装

npm install keytops-game-framework

快速开始

import { App } from 'keytops-game-framework';

await App.launch({
    injects: [],
});

App.launch() 会走框架入口,并通过 cocos.ts 自动完成 Cocos Creator 相关注入。

Cocos 注入说明

包根入口会执行 cocos.ts,默认注入以下实现:

  • Storage.KEY -> CocosStorageUtils
  • Timer.KEY -> TimerImpl
  • NativeHelper.KEY -> CocosNativeHelper
  • ViewManager.KEY -> CocosViewManager

这意味着在 Cocos Creator 环境中直接从包根导入并调用 App.launch(),即可使用默认的存储、计时器、原生桥接和视图管理实现。

主要导出能力

应用生命周期与基础设施

  • App
  • Application
  • Injector
  • Event
  • EventDispatcher
  • Pool
import { App, Injector } from 'keytops-game-framework';

await App.launch({
    injects: [],
});

const launchTimes = App.launchTimes;
const sessionId = App.sessionId;

网络与配置

  • net
  • NetManager
  • Server
  • SystemOnlineConfig
  • LevelOnlineConfig
  • HttpRequest
  • Socket
import { net } from 'keytops-game-framework';

net.logable = true;
await net.http.sendsync('/health', {
    method: 'get',
    responseType: 'json',
});

Publisher 平台能力

  • publisher
  • PublisherManager
  • PublisherManagerImpl
  • IPublisher
  • ILoginAble
  • IADAble
  • IShareAble
  • IPayAble
  • IDevice
  • 平台实现:WX*TT*KS*MY*Native*TK*
import { publisher } from 'keytops-game-framework';

publisher.enable();

const appId = publisher.appId;
const deviceInfo = publisher.device.deviceInfo;

存储与计时器

  • storage
  • Storage
  • StorageImpl
  • timer
  • Timer
  • TimerImpl
import { storage, timer } from 'keytops-game-framework';

storage.setGValue('music', true);
timer.loop(1000, null, () => {
    console.log('tick');
});

ECS / FSM / Task

  • ECS
  • ECSManager
  • Component
  • Entity
  • System
  • Fsm
  • FsmBase
  • FsmManager
  • Task
  • TaskQueue
  • TaskSequence

这些模块适合搭建带状态管理和任务编排的业务逻辑层。

Analytics

  • analytics
  • AnalyticsAble
  • KeytopsAnalyticsSender
  • ALiAnalyticsSender
  • LaunchAnalyticsAble
  • 关卡、广告、社交、会话等统计能力
import { analytics } from 'keytops-game-framework';

analytics.enable(true);
analytics.base.report('framework_ready', {
    name: 'boot',
});

View / Resource / Audio

  • View
  • Scene
  • CocosViewManager
  • CCSceneLoader
  • CCPViewLoader
  • ViewControl
  • TipsView
  • ResourceManager
  • AudioManager
  • AudioBusiness

这些模块提供 Cocos Creator 方向的界面、资源和音频能力。

扩展方式

追加自定义注入

import { App } from 'keytops-game-framework';

class CustomService {
    static KEY = 'CustomService';
}

await App.launch({
    injects: [CustomService],
});

扩展新的引擎适配层

如果后续要把同一套框架迁移到其他引擎,推荐参考 cocos.ts 的做法:

  1. 实现新的 IApplication
  2. 为存储、计时器、原生桥接、视图管理等注入对应实现
  3. 通过 Injector.inject(Application.KEY, NewEngineApplication) 注册入口

当前这个发布包仍然是以 Cocos Creator 为中心的游戏框架,不建议在 README 中把它表述为“现成支持多引擎发布”的通用产品。

构建

npm run build

构建产物:

  • dist/index.js
  • dist/index.d.ts

注意事项

  • 推荐直接从包根导入当前已经公开导出的符号,不要依赖未声明的内部路径
  • App.launch() 只接受 injects,README 示例不再使用不存在的 remoteConfigenableBidding 参数
  • 这是游戏框架层,不是 facade SDK;如果只需要 keytops.init()userconfiganalyticsadlevel,请使用 keytops-game-sdk
  • 引擎特定实现应依赖框架接口,不应反向耦合业务层