# mini-game-utils **Repository Path**: clengine/egret-utils ## Basic Information - **Project Name**: mini-game-utils - **Description**: 用于微信小游戏、QQ小游戏、头条小游戏、vivo小游戏的辅助库 - **Primary Language**: TypeScript - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 10 - **Forks**: 7 - **Created**: 2019-12-24 - **Last Updated**: 2025-06-08 ## Categories & Tags **Categories**: game-dev **Tags**: None ## README # game-utils 游戏支持库 该库涵盖两部分 - api库(包含微信小游戏,QQ小游戏,头条小游戏,vivo小游戏的sdk定义)可直接调用进行使用 | 文件名 | 介绍 | | ----------------------- | ----------- | | platform_basic.d.ts | 基础api | | platform_render.d.ts | 渲染api | | platform_ad.d.ts | 广告api | | platform_interface.d.ts | 界面api | | platform_open.d.ts | 开放接口api | - et库(包含常用的游戏辅助类及一些高级扩展方法) ## 适用范围 ### 支持引擎 - [x] egret - [ ] cocos - [ ] laya - [ ] pixi ### 支持小游戏 - [x] 微信小游戏 - [ ] QQ小游戏 - [ ] 头条小游戏 - [ ] vivo小游戏 ## 如何使用 ### 初始化核心类 `et.app` - 自动处理 `切换后台`/`返回前台` 事件 - 自动处理 `文本框黑色` 问题 ```typescript var app = new et.app(); app.init(this.stage); ``` ### 资源管理 ```typescript // 预加载资源组(这里只是预先把需要加载的资源缓存起来) et.egretRes.pushRes("preload", (event: egret.Event)=>{ // TODO: 资源进度通知事件 console.log("资源进度:" + Math.round(event.itemsLoaded / event.itemsTotal * 100) + "%", event.groupName); }, (event: egret.Event)=>{ // TODO: 资源加载完成事件 }, (event: egret.Event)=>{ // TODO: 资源加错报错事件 // 可无需写该方法 框架自动处理 }); // 也可直接这么加载资源 et.egretRes.pushRes("common"); // 开始加载资源(这里才是真正开始加载资源) // true: 加载完成后从资源缓存列表移除 et.egretRes.loadRes(true); ``` ### 初始化游戏信息 ```typescript // 为微信平台创建游戏信息 let appInfo = new et.AppInfo(et.Platform.Wxgame); appInfo.appId = "您的appid"; appInfo.bannerId = "您的bannerId"; appInfo.videoId = "您的激励视频Id"; // 使用上面核心类 et.app.instance.initApp(appInfo); ``` ### 显示banner广告 ```typescript // 需要为平台创建游戏信息后才可以显示 await et.app.instance.showBannerAd(); ``` ### 小游戏API > 所有小游戏无需关注命名空间,可一份代码发布到多个平台。命名空间全部调整为`api` 以下为各个平台示例最终输出的api,快速方便 ```typescript // wx.getSystemInfoSync() 微信小游戏写法 // qq.getSystemInfoSync() QQ小游戏写法 // tt.getSystemInfoSync() 头条小游戏写法 // qg.getSystemInfoSync() 快应用小游戏写法(vivo/oppo/小米) let systemInfo = api.getSystemInfoSync(); // 只需要使用api命名空间即可调用这些 ``` #### 目前支持API > 为了方便查找是否支持,进行分库处理 > > 注意: 以下只用于查询微信平台、别的平台暂未支持 ##### 基础库 | api名称 | 是否支持 | | --------------------------- | -------- | | `getSystemInfoSync` | 完全支持 | | `getSytemInfo` | 完全支持 | | `getUpdateManager` | 完全支持 | | `onShow` | 完全支持 | | `onHide` | 完全支持 | | `offShow` | 完全支持 | | `offHide` | 完全支持 | | `getLaunchOptionsSync` | 完全支持 | | `exitMiniProgram` | 完全支持 | | `onError` | 完全支持 | | `onAudioInterruptionEnd` | 完全支持 | | `onAudioInterruptionBegin` | 完全支持 | | `offError` | 完全支持 | | `offAudioInterruptionEnd` | 完全支持 | | `offAudioInterruptionBegin` | 完全支持 | | `onTouchStart` | 完全支持 | | `onTouchMove` | 完全支持 | | `onTouchEnd` | 完全支持 | | `onTouchCancel` | 完全支持 | | `offTouchStart` | 完全支持 | | `offTouchMove` | 完全支持 | | `offTouchEnd` | 完全支持 | | `offTouchCancel` | 完全支持 | | `triggerGC` | 完全支持 | | `markScene` | 完全支持 | | `getPerformance` | 完全支持 | | `loadSubpackage` | 完全支持 | | `setEnableDebug` | 完全支持 | | `getLogManager` | 完全支持 | | `console` | 完全支持 | | `LogManager` | 完全支持 | | `clearInterval` | 完全支持 | | `clearTimeout` | 完全支持 | | `setInterval` | 完全支持 | | `setTimeout` | 完全支持 | ##### 渲染库 | `createCanvas` | 完全支持 | | ----------------------------- | -------- | | `Canvas` | 完全支持 | | `RenderingContext` | 完全支持 | | `wxBindCanvasTexture` | 引擎提供 | | `setPreferredFramesPerSecond` | 完全支持 | | `cancelAnimationFrame` | 完全支持 | | `requestAnimationFrame` | 完全支持 | | `loadFont` | 完全支持 | | `getTextLineHeight` | 完全支持 | | `createImage` | 完全支持 | | `Image` | 完全支持 | - 广告库 | `createRewardedVideoAd` | 完全支持 | | ----------------------- | -------- | | `createInterstitialAd` | 完全支持 | | `createBannerAd` | 完全支持 | | `BannerAd` | 完全支持 | | `InterstitialAd` | 完全支持 | | `RewardedVideoAd` | 完全支持 | - 界面库 | `showToast` | 完全支持 | | --------------------------------- | -------- | | `showModal` | 完全支持 | | `showLoading` | 完全支持 | | `showActionSheet` | 完全支持 | | `hideToast` | 完全支持 | | `hideLoading` | 完全支持 | | `updateKeyboard` | 完全支持 | | `showKeyboard` | 完全支持 | | `onKeyboardInput` | 完全支持 | | `onKeyboardConfirm` | 完全支持 | | `onKeyboardComplete` | 完全支持 | | `offKeyboardInput` | 完全支持 | | `offKeyboardConfirm` | 完全支持 | | `offKeyboardComplete` | 完全支持 | | `hideKeyboard` | 完全支持 | | `setMenuStyle` | 完全支持 | | `getMenuButtonBoundingClientRect` | 完全支持 | | `onWindowResize` | 完全支持 | | `offWindowResize` | 完全支持 | - 网络库 | `request` | 完全支持 | | -------------- | -------- | | `RequestTask` | 完全支持 | | `downloadFile` | 完全支持 | | `DownloadTask` | 完全支持 | | `uploadFile` | 完全支持 | | `UploadTask` | 完全支持 | | `WebSocket` | 不支持 | | `UDP通信` | 不支持 | - 开放接口库 | `navigateToMiniProgram` | 完全支持 | | --------------------------------- | -------- | | `getUserInfo` | 完全支持 | | `getUserGameLabel` | 完全支持 | | `createUserInfoButton` | 完全支持 | | `UserInfo` | 完全支持 | | `UserInfoButton` | 完全支持 | | `login` | 完全支持 | | `checkSession` | 完全支持 | | `authorize` | 完全支持 | | `shareMessageToFriend` | 完全支持 | | `setUserCloudStorage` | 完全支持 | | `removeUserCloudStorage` | 完全支持 | | `onInteractiveStorageModified` | 完全支持 | | `modifyFriendInteractiveStorage` | 完全支持 | | `getUserInteractiveStorage` | 不支持 | | `getUserCloudStorage` | 不支持 | | `getSharedCanvas` | 不支持 | | `getPointialFriendList` | 不支持 | | `getGroupCloudStorage` | 不支持 | | `getFriendCloudStorage` | 不支持 | | `FriendInfo` | 不支持 | | `KVData` | 完全支持 | | `UserGameData` | 不支持 | | `onMessage` | 不支持 | | `getOpenDataContext` | 不支持 | | `OpenDataContext` | 不支持 | | `checkIsUserAdvisedToRest` | 不支持 | | `createFeedbackButton` | 不支持 | | `FeedBackButton` | 不支持 | | `openSetting` | 不支持 | | `getSetting` | 不支持 | | `createOpenSettingButton` | 不支持 | | `AuthSetting` | 不支持 | | `OpenSettingButton` | 不支持 | | `createGameClubButton` | 不支持 | | `GameClubButton` | 不支持 | | `openCustomerServiceConversation` | 不支持 | | `getWeRunData` | 不支持 | | `openCard` | 不支持 | | `addCard` | 不支持 | | `reportMonitor` | 不支持 | | `requestSubscribeSystemMessage` | 不支持 | | `requestSubscribeMessage` | 不支持 |