Commit 5cb0e4cc authored by 张世斌's avatar 张世斌

首次提交

parent 3b680f1f
No preview for this file type
This diff is collapsed.
......@@ -2,8 +2,6 @@
cocos creator技术框架下的H5互动模板框架脚手架,基于cocos creator实现快速开发基于绘玩云的H5互动课件。
[视频教程传送门](https://www.bilibili.com/video/BV1Dq4y1t7n5/)
# 使用简介
## 前期准备
......@@ -51,7 +49,21 @@ npm start
```
* 打开浏览器:http://staging-teach.ireadabc.com/template_ci/debug
* [点击查看调试视频教程](https://www.bilibili.com/video/BV1Dq4y1t7n5?p=8)
* 点击右上角齿轮,选择技术选型、调试模式选择“普通”
### 互动模板
* 找到项目根路径下 index.html 文件
* 在引入JS的位置将air.js改为air_online_open.js
* 启动本地服务
```
npm start
```
* 打开浏览器:http://staging-teach.ireadabc.com/template_ci/debug
* 点击右上角齿轮,选择技术选型、调试模式选择“互动”
* 左侧老师、右侧学生
### 真机调试
......@@ -69,11 +81,4 @@ npm start
* 手机和电脑连接同一个Wifi
* 打开调试app,根据提示输入IP地址,点击开始就可以在手机上预览模板了
* 使用 console.log("==调试信息=="); 可以打印日志进行必要的调试
* 点击左上角 “logcat” 可以查看运行日志,(logcat是可以按住拖动的, 所以不用考虑UI遮挡问题)
### 注意事项及常见问题
* 项目里所有文件及文件夹的命名方式要注意不能包含空格、汉字、减号
* 项目里尽量不要使用setTimeout、setInterval等定时器,如果使用了记得在onDestroy中释放掉(onDestroy 是指CocosCreator的生命周期钩子)
* 理论上禁止使用全局变量,因为模板到线上会进行组装,常见问题是一个模板使用多次造成全局变量被读脏
* 使用 this.log("==调试信息=="); 可以打印日志进行必要的调试
\ No newline at end of file
{"ver":"1.1.2","uuid":"c35bb2f6-f24a-4850-ae44-643f2fdc7541","isBundle":false,"bundleName":"","priority":1,"compressionType":{},"optimizeHotUpdate":{},"inlineSpriteFrames":{},"isRemoteBundle":{"ios":false,"android":false},"subMetas":{}}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "f0680ae0-c079-45ef-abd7-9e63d90b982b",
"uuid": "d965eb93-2a37-490e-989b-d163f50b6a11",
"downloadMode": 0,
"duration": 0.130612,
"duration": 0.168,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "38b13873-be7b-4f9a-8f74-68d7eb65800d",
"downloadMode": 0,
"duration": 0.20898,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "f8db83d2-5828-4bff-ae64-110f2ab91b6e",
"downloadMode": 0,
"duration": 0.972,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "c5dcb848-8cb1-4a03-9edf-9166bf91ceea",
"downloadMode": 0,
"duration": 10.615438,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "361b2d4a-7d66-4cdb-ac33-0ebc2e1c6aaf",
"downloadMode": 0,
"duration": 13.061224,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "26b3ea63-59ba-45eb-982e-a83201422090",
"downloadMode": 0,
"duration": 2.196,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "ceb12779-73c5-4001-82b2-6444cee1292f",
"downloadMode": 0,
"duration": 3.096,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "16c77e39-ee05-4f1b-83c2-10ba41022cdf",
"downloadMode": 0,
"duration": 0.731429,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "33970e44-e601-4604-ba4e-42f7f0ae3ea3",
"downloadMode": 0,
"duration": 4.650667,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "808d1988-5708-451a-b21d-dbe7f8034862",
"downloadMode": 0,
"duration": 4.794667,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "7437ef52-3b02-4df3-9961-8c9bcc16515e",
"downloadMode": 0,
"duration": 4.650667,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "069267b7-fba1-49a3-a4a2-f2b7d3cb12bb",
"downloadMode": 0,
"duration": 4.650667,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "c4249471-e8d9-4ee9-aae9-de609b902168",
"downloadMode": 0,
"duration": 4.650667,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "3b82301e-b878-4d1c-8243-a677bd877434",
"downloadMode": 0,
"duration": 0.938688,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "c39846ad-f443-4830-a98c-47ddf868d423",
"downloadMode": 0,
"duration": 8.718667,
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.0.1",
"uuid": "8fb2d623-ea9a-465b-a666-66623353eb18",
"subMetas": {}
}
\ No newline at end of file
{"name":"mao","imagePath":"mao_tex.png","SubTexture":[{"name":"猫01/影子","x":1,"height":66,"y":343,"width":337},{"name":"猫01/尾巴","x":1,"height":109,"y":188,"width":175},{"name":"猫01/右腿","x":178,"height":117,"y":188,"width":104},{"name":"猫01/左腿","x":1,"height":115,"y":569,"width":64},{"name":"猫01/右手","x":427,"height":122,"y":590,"width":69},{"name":"猫01/左手","x":301,"height":74,"y":590,"width":124},{"name":"猫01伸/左手伸直","x":299,"height":169,"y":1,"width":168},{"name":"猫01伸/右手伸直","x":299,"height":169,"y":172,"width":168},{"name":"猫01/身体","x":340,"height":180,"y":343,"width":122},{"name":"猫01/领带","x":1,"height":156,"y":411,"width":120},{"name":"猫01/右耳","x":155,"height":76,"y":602,"width":90},{"name":"猫01/左耳","x":67,"height":85,"y":602,"width":86},{"name":"猫01/组_1","x":1,"height":185,"y":1,"width":296},{"name":"猫01/右眼","x":1,"height":60,"y":686,"width":59},{"name":"猫01/右眉毛","x":67,"height":5,"y":595,"width":33},{"name":"猫01/左眼","x":247,"height":60,"y":666,"width":59},{"name":"猫01/左眉毛","x":247,"height":12,"y":602,"width":31},{"name":"猫01/眼镜","x":301,"height":63,"y":525,"width":170},{"name":"猫01/胡子","x":123,"height":85,"y":515,"width":176},{"name":"猫01/鼻子","x":67,"height":24,"y":569,"width":28},{"name":"猫01/嘴","x":1,"height":30,"y":299,"width":65},{"name":"猫01/帽子","x":123,"height":102,"y":411,"width":158}],"height":1024,"width":512}
\ No newline at end of file
{
"ver": "1.0.1",
"uuid": "7c83def9-961d-4141-97aa-4b109dddeb0f",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "406732a3-eaf9-4833-8a01-542ad1189a3e",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 512,
"height": 1024,
"platformSettings": {},
"subMetas": {
"mao_tex": {
"ver": "1.0.4",
"uuid": "d2fab846-619a-43af-98c8-e5d62448ef97",
"rawTextureUuid": "406732a3-eaf9-4833-8a01-542ad1189a3e",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": -7.5,
"offsetY": 138.5,
"trimX": 1,
"trimY": 1,
"width": 495,
"height": 745,
"rawWidth": 512,
"rawHeight": 1024,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "1.1.0",
"uuid": "c551970e-b095-45f3-9f1d-25cde8b8deb1",
"uuid": "b7cb916a-ffb9-41d4-a434-670da0dbd4b0",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "c32c4466-c4c2-4f94-a5af-b8ef0d3c4bc9",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.0.8",
"uuid": "771c13cf-dd4a-4c25-9dca-413a319550cf",
"isPlugin": true,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "0b195014-889e-4a47-81a3-8ce6d559c855",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "276fdbf4-33a8-4baa-a513-a660d8ae6f1d",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
cc.Class({
extends: cc.Component,
properties: {
},
ctor() {
this._timeoutIds = [];
this._intervalIds = [];
this._maxRate = 0;
},
// 生命周期 onLoad
onLoad() {
this.initSize();
},
_designSize: null, // 设计分辨率
_frameSize: null, // 屏幕分辨率
_mapScaleMin: null, // 场景中常用缩放(取大值)
_mapScaleMax: null, // 场景中常用缩放(取小值)
_cocosScale: null, // cocos 自缩放 (较少用到)
initSize() {
// 注意cc.winSize只有在适配后(修改fitHeight/fitWidth后)才能获取到正确的值,因此使用cc.getFrameSize()来获取初始的屏幕大小
let screen_size = cc.view.getFrameSize().width / cc.view.getFrameSize().height
let design_size = cc.Canvas.instance.designResolution.width / cc.Canvas.instance.designResolution.height
let f = screen_size >= design_size
cc.Canvas.instance.fitHeight = f
cc.Canvas.instance.fitWidth = !f
const frameSize = cc.view.getFrameSize();
this._frameSize = frameSize;
this._designSize = cc.view.getDesignResolutionSize();
let sx = cc.winSize.width / frameSize.width;
let sy = cc.winSize.height / frameSize.height;
this._cocosScale = Math.min(sx, sy);
sx = frameSize.width / this._designSize.width;
sy = frameSize.height / this._designSize.height;
this._mapScaleMin = Math.min(sx, sy) * this._cocosScale;
this._mapScaleMax = Math.max(sx, sy) * this._cocosScale;
},
// 生命周期 start
async start() {
this.updateLabel('创建房间中');
this.progressTo(0.1, 1);
await this.asyncDelay(1);
this.updateLabel('匹配小伙伴中');
},
async initView() {
this.setMaxPlayerNumber(5);
},
setMaxPlayerNumber(number) {
this._maxPlayerNum = number;
},
addPlayer(name, isSelf, headUrl) {
console.log('name = ' + name);
const layout = cc.find('layout', this.node);
const headNode = cc.instantiate(cc.find('head', this.node));
headNode.x = 0;
headNode.y = 0;
headNode.active = true;
const frameSelf = cc.find('frame_self', headNode);
if (!isSelf) {
frameSelf.opacity = 0;
}
const nameLabel = cc.find('name', headNode);
nameLabel.getComponent(cc.Label).string = name;
const headImg = cc.find('mask/headImg', headNode);
this.loadSpriteByUrl(headImg, headUrl, () => {
const scale = Math.max(
headImg.parent.width / headImg.width,
headImg.parent.height / headImg.height
);
headImg.scale = scale;
});
layout.addChild(headNode);
const rate = Math.min(1, layout.children.length / this._maxPlayerNum);
if (rate == 1) {
this.updateLabel('同步中');
}
this.progressTo(rate, 3);
},
onLoadFinished(func) {
this._onLoadFinishFunc = func;
},
async asyncDelay(time) {
return new Promise((resolve, reject) => {
try {
this._timeoutIds.push(setTimeout(() => {
resolve();
}, time * 1000));
} catch (e) {
reject(e);
}
});
},
updateLabel(str) {
const label = cc.find('label', this.node).getComponent(cc.Label);
if (label.tweenAction) {
label.tweenAction.stop();
}
label.tweenAction = cc.tween(label)
.set({ string: `${str}` })
.delay(0.4)
.set({ string: `${str}.` })
.delay(0.4)
.set({ string: `${str}..` })
.delay(0.4)
.set({ string: `${str}...` })
.delay(0.4)
.union()
.repeatForever()
.start();
},
progressTo(rate, time) {
this._maxRate = Math.max(this._maxRate, rate);
const duration = Math.max(time + this.RandomInt(-1, 1), 1);
const progress = cc.find('progressBar', this.node).getComponent(cc.ProgressBar);
if (progress.tweenAction) {
progress.tweenAction.stop();
}
const easingList = [
'linear',
'quadInOut',
'cubicInOut',
];
progress.tweenAction = cc.tween(progress)
.to(duration, { progress: this._maxRate }, { easing: easingList[this.RandomInt(easingList.length)] })
.call(() => {
if (rate == 1) {
if (this._onLoadFinishFunc) {
this._onLoadFinishFunc();
}
this.node.active = false;
}
})
.start();
},
RandomInt(a, b = 0) {
let max = Math.max(a, b);
let min = Math.min(a, b);
return Math.floor(Math.random() * (max - min) + min);
},
// ------------------------------------------------
loadSpriteByUrl(node, url, cb) {
cc.loader.load({ url }, (err, img) => {
if (!node) {
cb && cb();
}
const spriteFrame = new cc.SpriteFrame(img)
const spr = node.getComponent(cc.Sprite);
spr.spriteFrame = spriteFrame;
if (cb) {
cb();
}
});
},
currentPlayedAudioId: null,
stopCurrentPlayedAudio() {
if (this.currentPlayedAudioId !== null) {
cc.audioEngine.stop(this.currentPlayedAudioId);
this.currentPlayedAudioId = null;
}
},
playEffect(name, cb) {
this.stopCurrentPlayedAudio();
const audioNode = cc.find(`audios/${name}`);
const audioClip = audioNode.getComponent(cc.AudioSource).clip;
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
this.currentPlayedAudioId = audioId;
if (cb) {
cc.audioEngine.setFinishCallback(audioId, cb);
}
},
playAudioByUrl(audio_url, cb = null) {
if (!audio_url) {
if (cb) {
cb();
}
return;
}
this.stopCurrentPlayedAudio();
cc.assetManager.loadRemote(audio_url.toLowerCase(), (err, audioClip) => {
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
this.currentPlayedAudioId = audioId;
if (cb) {
cc.audioEngine.setFinishCallback(audioId, cb);
}
});
},
_timeoutIds: null,
_intervalIds: null,
// 生命周期
onDestroy() {
this._timeoutIds.forEach(id => {
clearTimeout(id);
});
this._intervalIds.forEach(id => {
clearInterval(id);
});
},
});
{
"ver": "1.0.8",
"uuid": "f8b451ff-857c-4ca8-9870-866bc5154a29",
"uuid": "b92c04a8-ba16-48fd-9bdd-693e35c035a1",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
......
{
"ver": "1.2.9",
"uuid": "3fc9f999-6ccd-4605-869d-34e1d9d8a6b8",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"readonly": false,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "e4e8a9dd-5f83-458a-9a80-90a05aa7cb3d",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.0",
"uuid": "b2c8b99b-9591-4c2d-8fe0-34536a5d109d",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "e1b4d971-9876-4832-803a-5a321964a78b",
"uuid": "02de8acc-6171-4d60-946b-d1a3804ed47e",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1280,
"height": 720,
"width": 2176,
"height": 1600,
"platformSettings": {},
"subMetas": {
"bg": {
"ver": "1.0.4",
"uuid": "8288e3d4-4c75-4b27-8f01-f7014417f4dd",
"rawTextureUuid": "e1b4d971-9876-4832-803a-5a321964a78b",
"uuid": "2b60a02b-c538-4d23-b825-dbb56266d722",
"rawTextureUuid": "02de8acc-6171-4d60-946b-d1a3804ed47e",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
......@@ -22,10 +22,10 @@
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1280,
"height": 720,
"rawWidth": 1280,
"rawHeight": 720,
"width": 2176,
"height": 1600,
"rawWidth": 2176,
"rawHeight": 1600,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
{
"ver": "1.1.0",
"uuid": "bdac295a-5671-4f2e-a096-d1f0cbe4355b",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "93314f1c-96ce-4dfe-93c6-d7ffcfc77f30",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "point",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1568,
"height": 32,
"platformSettings": {},
"subMetas": {
"progress_bar": {
"ver": "1.0.4",
"uuid": "1ffe8e4b-468a-4a73-a829-e33aa42309c6",
"rawTextureUuid": "93314f1c-96ce-4dfe-93c6-d7ffcfc77f30",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1568,
"height": 32,
"rawWidth": 1568,
"rawHeight": 32,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "c1db59a1-6c38-4857-9caa-08e36b64b83d",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "point",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1578,
"height": 42,
"platformSettings": {},
"subMetas": {
"progress_bg": {
"ver": "1.0.4",
"uuid": "e9bfed17-24da-41ab-903a-673485e53dd1",
"rawTextureUuid": "c1db59a1-6c38-4857-9caa-08e36b64b83d",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1578,
"height": 42,
"rawWidth": 1578,
"rawHeight": 42,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "91e2aa0f-7a45-40f5-95a3-adae8d0f7f62",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": true,
"genMipmaps": false,
"packable": true,
"width": 280,
"height": 280,
"platformSettings": {},
"subMetas": {
"tx_01": {
"ver": "1.0.4",
"uuid": "6a417c79-c3c4-4a2d-b1b7-ab8e0a09b4be",
"rawTextureUuid": "91e2aa0f-7a45-40f5-95a3-adae8d0f7f62",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 280,
"height": 280,
"rawWidth": 280,
"rawHeight": 280,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "9a79969a-0506-48d4-bc98-3c05d109b027",
"uuid": "3482320e-2529-4712-bffc-a12b90e55295",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 61,
"height": 67,
"width": 258,
"height": 258,
"platformSettings": {},
"subMetas": {
"btn_left": {
"tx_01zw": {
"ver": "1.0.4",
"uuid": "ce19457d-e8f3-4c38-ae3e-d4b99208ddb5",
"rawTextureUuid": "9a79969a-0506-48d4-bc98-3c05d109b027",
"uuid": "cfc038a5-f26a-4c08-8358-530c28aa0098",
"rawTextureUuid": "3482320e-2529-4712-bffc-a12b90e55295",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
......@@ -22,10 +22,10 @@
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 61,
"height": 67,
"rawWidth": 61,
"rawHeight": 67,
"width": 258,
"height": 258,
"rawWidth": 258,
"rawHeight": 258,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
{
"ver": "2.3.5",
"uuid": "d582359e-924e-4ee9-9964-1fc4bb417e71",
"uuid": "25db951d-e25d-41a6-b09b-3fce9fa91ccb",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 61,
"height": 67,
"width": 388,
"height": 388,
"platformSettings": {},
"subMetas": {
"btn_right": {
"tx_xuanzhong": {
"ver": "1.0.4",
"uuid": "e5a2dbaa-a677-4a32-90d7-a1b057d7fb59",
"rawTextureUuid": "d582359e-924e-4ee9-9964-1fc4bb417e71",
"uuid": "4b19e144-bb23-4fcd-abc4-71e0e99e89a8",
"rawTextureUuid": "25db951d-e25d-41a6-b09b-3fce9fa91ccb",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": -0.5,
"offsetY": 0.5,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 60,
"height": 66,
"rawWidth": 61,
"rawHeight": 67,
"width": 388,
"height": 388,
"rawWidth": 388,
"rawHeight": 388,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
This diff is collapsed.
{
"ver": "1.2.9",
"uuid": "0737ce42-24f0-45c6-8e1a-8bdab4f74ba3",
"uuid": "1ef174b1-e274-4c5a-b9c2-e6d0c9b94c2a",
"asyncLoadAssets": false,
"autoReleaseAssets": true,
"subMetas": {}
......
This diff is collapsed.
{
"ver": "1.0.8",
"uuid": "408a67f8-65fa-4cf1-8cf2-83e20e1a0fd5",
"uuid": "f78cb858-cda1-471d-87fe-0fb345049f4b",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
......
import { RandomInt } from "../script/util";
export class NetworkHelper {
_eventListeners: any = {};
ctor() { }
on(eventName, func) {
this._eventListeners[eventName] = func;
}
async init(roomType: string, maxPlayers: number) {
this.initRoom();
try {
return await this.joinRoom(roomType, maxPlayers);
} catch (e) {
await this.initListener();
this.initRoom();
return await this.joinRoom(roomType, maxPlayers);
}
}
async startGame() {
await this.startFrameSync();
await this.closeRoom();
}
async stopGame() {
await this.stopFrameSync();
await this.leaveRoom();
}
getRoomInfo() {
return this.room.roomInfo;
}
initListener() {
return new Promise((resolve, reject) => {
const gameId = "obg-i4ql53h1"; //替换为控制台上的 游戏 ID
const secretKey = "060d81c7abaf24c8ce2afc5a725c152062676d35"; //替换为控制台上的 游戏 Key
const serverUrl = "i4ql53h1.wxlagame.com"; //替换为控制台上的 域名
const gameInfo = {
gameId: gameId,
openId: "openid_test" + Math.random(), //自定义的用户唯一ID
secretKey: secretKey
};
const config = {
url: serverUrl,
reconnectMaxTimes: 5,
reconnectInterval: 1000,
resendInterval: 1000,
resendTimeout: 10000,
cacertNativeUrl: ""
};
MGOBE.DebuggerLog.enable = false;
// 如果是原生平台,则加载 Cert 证书,否则会提示 WSS 错误
if (cc.sys.isNative) {
let cacertFile;
const cacertNode = cc.find('cacertNode');
if (cacertNode) {
cacertFile = cacertNode.getComponent('cacert').cacertFile;
}
if (!cacertFile) {
this.log('没有cacertFile!!!');
}
config.cacertNativeUrl = cc.loader.md5Pipe && cc.ENGINE_VERSION < "2.4.0" ?
cc.loader.md5Pipe.transformURL(cacertFile.nativeUrl) :
cacertFile.nativeUrl;
}
MGOBE.Listener.init(gameInfo, config, event => {
this.log(JSON.stringify(event));
if (event.code !== 0) {
this.log("初始化失败: " + event.code);
reject();
return;
}
this.log("初始化成功");
resolve(null);
});
});
}
room: MGOBE.Room;
initRoom() {
this.room = new MGOBE.Room();
MGOBE.Listener.add(this.room);
this.room.onJoinRoom = this.onJoinRoom.bind(this);
this.room.onLeaveRoom = this.onLeaveRoom.bind(this);
this.room.onRecvFromClient = this.onRecvFromClient.bind(this);
this.room.onRecvFrame = this.onRecvFrame.bind(this);
this.room.onStartFrameSync = this.onStartFrameSync.bind(this);
this.room.onStopFrameSync = this.onStopFrameSync.bind(this);
this.room.onRecvFromGameSvr = this.onRecvFromGameSvr.bind(this);
this.log('this.room = ' + JSON.stringify(this.room.roomInfo));
}
joinRoom(roomType: string, maxPlayers: number, customData: string = '') {
return new Promise((resolve, reject) => {
const playerName = "Player-" + Math.round( Math.random() * 1000);
const playerInfo = {
name: playerName,
customPlayerStatus: 0,
customProfile: customData,
};
const matchRoomPara = {
playerInfo,
maxPlayers: maxPlayers,
roomType: roomType
};
this.room.matchRoom(matchRoomPara, event => {
console.log(event);
if (event.code === 0) {
cc.log("匹配成功");
const player = event.data.roomInfo.playerList.find(player => player.name == playerName);
resolve(player.id);
} else {
cc.log("匹配失败");
reject();
}
});
});
}
leaveRoom() {
return new Promise((resolve, reject) => {
this.room.leaveRoom({}, event => {
console.log(event);
if (event.code === 0) {
cc.log("退房成功", this.room.roomInfo.id);
this.room.initRoom();
resolve(null);
}
});
});
}
closeRoom() {
return new Promise((resolve, reject) => {
this.room.changeRoom({ isForbidJoin: true }, (event) => {
console.log('关门')
console.log(event);
resolve(null);
});
});
}
sendMessage(msg) {
if (!msg) {
return;
}
if (typeof (msg) == 'object') {
msg = JSON.stringify(msg);
}
const sendToClientPara = {
recvType: MGOBE.ENUM.RecvType.ROOM_ALL,
recvPlayerList: [],
msg: msg
};
this.room.sendToClient(sendToClientPara, event => console.log(event));
}
startFrameSync() {
return new Promise((resolve, reject) => {
this.room.startFrameSync({}, event => {
console.log(event);
if (event.code === 0) {
cc.log("开始帧同步成功,请到控制台查看具体帧同步信息");
resolve(null);
} else {
reject();
}
});
});
}
stopFrameSync() {
return new Promise((resolve, reject) => {
this.room.stopFrameSync({}, event => {
console.log(event);
if (event.code === 0) {
cc.log("停止帧同步成功");
resolve(null);
} else {
reject(event.code);
}
});
});
}
sendToServer() {
const sendToGameServerPara = {
data: {
cmd: 1
}
};
this.room.sendToGameSvr(sendToGameServerPara, event => console.log(event));
}
sendFrame(data: any) {
this.room.sendFrame({ data }, err => {
if (err.code != 0) {
console.log("err", err)
}
});
}
sendEvent(key: String, data: Object) {
this.sendFrame({key, data});
}
onJoinRoom(event) {
if (this._eventListeners['playerJoin']) {
this._eventListeners['playerJoin'](event);
}
this.room.roomInfo = event.data.roomInfo;
console.log("新玩家加入", event.data.joinPlayerId);
}
onLeaveRoom(event) {
if (this._eventListeners['playerLeave']) {
this._eventListeners['playerLeave'](event);
}
this.room.roomInfo = event.data.roomInfo;
console.log("玩家退出", event.data.leavePlayerId);
}
onRecvFromClient() { }
onRecvFrame(event) {
if (this._eventListeners['frameEvent']) {
this._eventListeners['frameEvent'](event);
}
}
onStartFrameSync(event) {
if (this._eventListeners['gameStart']) {
this._eventListeners['gameStart'](event);
}
}
onStopFrameSync(event) { }
onRecvFromGameSvr() { }
log(str) {
const node = cc.find('middleLayer');
if (node) {
node.getComponent('middleLayer').log(str);
} else {
cc.log(str);
}
}
async onDestroy() {
try {
this.log('onDestroy1')
MGOBE.Listener.clear();
await this.stopGame();
this.log('onDestroy2')
} catch (e) {
this.log(JSON.stringify(e));
}
}
}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "3b5661aa-abb8-448c-b4e5-22ce7bbb78b7",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
export const defaultData =
{
"items": [
{
"words": "aAcBaCbA",
"answers": "0147",
"audio_url": "http://staging-teach.cdn.ireadabc.com/18bf8207ddea222c9b82c68f2549dadc.mp3"
},
{
"words": "aAcBaCbA",
"answers": "0147",
"audio_url": "http://staging-teach.cdn.ireadabc.com/18bf8207ddea222c9b82c68f2549dadc.mp3"
},
],
"time": "10",
"audio_url": "",
"title": ""
}
export class GameServer {
userArr = [];
resultArr = [];
gameDuration = 20;
userMax = 6;
networkHelper;
constructor() {
}
setNetworkHelper(nh) {
this.networkHelper = nh;
this.registerListener();
}
registerListener() {
const c = window.courseware;
if (!c) {
return;
}
// // 收到1条结果
// c.onEvent('send_result', (data, next) => {
// this.resultArr.push(data);
// next();
// });
// c.onEvent('send_good', (data, next) => {
// this.sendEvent('get_good', data)
// next();
// });
}
// 添加一个用户
addUser(data) {
console.log('addUser ~~~~~~~ ');
if (this.userArr.length >= this.userMax) {
return false;
}
this.userArr.push(data);
if (this.userArr.length >= this.userMax) {
this.gameStart();
}
return true;
}
gameStart() {
// this.sendEvent('game_start', {});
console.log(' in gameStart closeRoom')
this.networkHelper.closeRoom().then(() => {
console.log(' in closeRoom cb')
this.networkHelper.sendFrame({ key: 'game_start', data: {} })
});
}
gameTimeStart() {
const delayTime = 3;
this._timeoutIds.push(setTimeout(() => {
this.gameEnd();
}, (this.gameDuration + delayTime) * 1000));
}
gameEnd() {
const c = window.courseware;
if (!c) {
return;
}
console.log('getAnswer start ..')
c.getAnswer({ templateName: 'OP10_online' }, (res) => {
console.log('getAnswer res: ', res);
if (res) {
this.sendEvent('game_end', res);
}
})
// this.sendEvent('game_end', this.resultArr);
}
sendEvent(evtName, data) {
const c = window.courseware;
if (!c) {
return;
}
c.sendEvent(evtName, data);
}
_timeoutIds = [];
_intervalIds = [];
// 生命周期
onDestroy() {
this._timeoutIds.forEach(id => {
clearTimeout(id);
});
this._intervalIds.forEach(id => {
clearInterval(id);
});
}
}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "5cf00a57-8f1b-4432-9f83-df08efe40931",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
export function playDragonBoneAnimation(node, animationName, time = 1, onFinish = null, onFrameEvent = null) {
const armatureDisplay = node.getComponent(dragonBones.ArmatureDisplay);
armatureDisplay.once(dragonBones.EventObject.COMPLETE, () => {
if (onFinish) {
onFinish();
}
});
armatureDisplay.on(dragonBones.EventObject.FRAME_EVENT, (event) => {
if (onFrameEvent) {
onFrameEvent(event);
}
});
armatureDisplay.playAnimation(animationName, time);
return armatureDisplay;
}
export function getPosByAngle(angle, len) {
const radian = angle * Math.PI / 180;
......@@ -161,11 +177,46 @@ export function getSprNodeByUrl(url, cb) {
})
}
export function popParticle(node, pos, sprNode, mapScale=1, num=30, lenMin=100, lenChange=300) {
for (let i=0; i<num; i++) {
const particleNode = cc.instantiate(sprNode);
particleNode.x = pos.x;
particleNode.y = pos.y;
particleNode.z = 35;
particleNode.parent = node;
const targetS = 0.05 + Math.random() * 0.85;
particleNode.scale = mapScale * targetS;
const targetR = Math.random() * 360;
particleNode.rotation = targetR;
const targetO = 200 + Math.random() * 55;
particleNode.opacity = targetO;
const targetP = getPosByAngle(Math.random() * 360, (lenMin + Math.random() * lenChange) * mapScale );
let time = 1;
const timeChange = 1 * Math.random();
time += timeChange;
cc.tween(particleNode)
.by(time, { x: targetP.x, y: targetP.y }, {easing: 'expoOut'})
.to(time/4, { opacity: 0 }, {easing: 'sineIn'})
.start();
}
}
export function playAudio(audioClip, cb = null) {
if (audioClip) {
const audioId = cc.audioEngine.playEffect(audioClip, false);
const audioId = cc.audioEngine.playEffect(audioClip, false, 0.8);
if (cb) {
cc.audioEngine.setFinishCallback(audioId, () => {
cb();
......@@ -177,12 +228,9 @@ export function playAudio(audioClip, cb = null) {
export async function asyncDelay(time) {
return new Promise((resolve, reject) => {
try {
cc.tween(cc.find('Canvas'))
.delay(time)
.call(()=>{
resolve(null);
})
.start();
setTimeout(() => {
resolve();
}, time * 1000);
} catch (e) {
reject(e);
}
......@@ -299,7 +347,7 @@ export async function asyncTweenTo(node, duration, obj, ease = undefined) {
cc.tween(node)
.to(duration, obj, ease)
.call(() => {
resolve(null);
resolve();
})
.start();
} catch (e) {
......@@ -314,7 +362,7 @@ export async function asyncTweenBy(node, duration, obj, ease = undefined) {
cc.tween(node)
.by(duration, obj, ease)
.call(() => {
resolve(null);
resolve();
})
.start();
} catch (e) {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment