Commit 934dd06d authored by Lwd's avatar Lwd

aaaa

parent cb1367da
{
"ver": "1.1.2",
"uuid": "a878983d-6b10-4de7-915d-86629281850a",
"isBundle": true,
"bundleName": "resources",
"priority": 8,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "c35bb2f6-f24a-4850-ae44-643f2fdc7541",
"uuid": "5e84bf78-6d16-45a9-91c1-59c221adf5c0",
"isBundle": false,
"bundleName": "",
"priority": 1,
......
{
"ver": "1.1.0",
"uuid": "4fe6019f-f84c-439f-97b8-a4cfe2ddc7ca",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.0",
"uuid": "f0214b38-1b2a-41ef-aa3e-1d6949fd3b12",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.0",
"uuid": "1fc51dd0-d295-4a33-8b99-adcb5978c932",
"subMetas": {}
}
\ No newline at end of file
import { onHomeworkFinish } from "../script/util";
import { defaultData } from "../script/defaultData";
cc.Class({
extends: cc.Component,
properties: {
},
// 生命周期 onLoad
onLoad() {
this.initSceneData();
this.initSize();
},
_imageResList: null,
_audioResList: null,
_animaResList: null,
initSceneData() {
this._imageResList = [];
this._audioResList = [];
this._animaResList = [];
},
_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
start() {
let getData = this.getData.bind(this);
if (window && window.courseware) {
getData = window.courseware.getData;
}
getData((data) => {
console.log('data:', data);
this.data = data || this.getDefaultData();
this.data = JSON.parse(JSON.stringify(this.data))
this.preloadItem()
})
},
getData(func) {
if (window && window.courseware) {
window.courseware.getData(func, 'scene');
return;
}
const middleLayer = cc.find('middleLayer');
if (middleLayer) {
const middleLayerComponent = middleLayer.getComponent('middleLayer');
middleLayerComponent.getData(func);
return;
}
func(this.getDefaultData());
},
getDefaultData() {
return defaultData;
},
preloadItem() {
this.addPreloadImage();
this.addPreloadAudio();
this.addPreloadAnima();
this.preload();
},
addPreloadImage() {
this._imageResList.push({ url: this.data.pic_url });
this._imageResList.push({ url: this.data.pic_url_2 });
},
addPreloadAudio() {
this._audioResList.push({ url: this.data.audio_url });
},
addPreloadAnima() {
},
preload() {
const preloadArr = this._imageResList.concat(this._audioResList).concat(this._animaResList);
cc.assetManager.loadAny(preloadArr, null, null, (err, data) => {
this.loadEnd();
if (window && window["air"]) {
window["air"].hideAirClassLoading();
}
cc.debug.setDisplayStats(false);
});
},
loadEnd() {
this.initData();
this.initAudio();
this.initView();
// this.initListener();
},
_cantouch: null,
initData() {
// 所有全局变量 默认都是null
this._cantouch = true;
},
audioBtn: null,
initAudio() {
const audioNode = cc.find('Canvas/res/audio');
const getAudioByResName = (resName) => {
return audioNode.getChildByName(resName).getComponent(cc.AudioSource);
}
this.audioBtn = getAudioByResName('btn');
},
initView() {
this.initBg();
this.initPic();
this.initBtn();
this.initIcon();
},
initBg() {
const bgNode = cc.find('Canvas/bg');
bgNode.scale = this._mapScaleMax;
},
pic1: null,
pic2: null,
initPic() {
const canvas = cc.find('Canvas');
const maxW = canvas.width * 0.7;
this.getSprNodeByUrl(this.data.pic_url, (sprNode) => {
const picNode1 = sprNode;
picNode1.scale = maxW / picNode1.width;
picNode1.baseX = picNode1.x;
canvas.addChild(picNode1);
this.pic1 = picNode1;
const labelNode = new cc.Node();
labelNode.color = cc.Color.YELLOW;
const label = labelNode.addComponent(cc.Label);
label.string = this.data.text;
label.fontSize = 60;
label.lineHeight = 60;
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent('cc.Label').font;
picNode1.addChild(labelNode);
});
this.getSprNodeByUrl(this.data.pic_url_2, (sprNode) => {
const picNode2 = sprNode;
picNode2.scale = maxW / picNode2.width;
canvas.addChild(picNode2);
picNode2.x = canvas.width;
picNode2.baseX = picNode2.x;
this.pic2 = picNode2;
const labelNode = new cc.Node();
const label = labelNode.addComponent(cc.RichText);
const size = 60
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent(cc.Label).font;
label.string = `<outline color=#751e00 width=4><size=${size}><color=#ffffff>${this.data.text}</color></size></outline>`
label.lineHeight = size;
picNode2.addChild(labelNode);
});
},
initIcon() {
const iconNode = this.getSprNode('icon');
iconNode.zIndex = 5;
iconNode.anchorX = 1;
iconNode.anchorY = 1;
iconNode.parent = cc.find('Canvas');
iconNode.x = iconNode.parent.width / 2 - 10;
iconNode.y = iconNode.parent.height / 2 - 10;
iconNode.on(cc.Node.EventType.TOUCH_START, () => {
this.playAudioByUrl(this.data.audio_url);
})
},
curPage: null,
initBtn() {
this.curPage = 0;
const bottomPart = cc.find('Canvas/bottomPart');
bottomPart.zIndex = 5; // 提高层级
bottomPart.x = bottomPart.parent.width / 2;
bottomPart.y = -bottomPart.parent.height / 2;
const leftBtnNode = bottomPart.getChildByName('btn_left');
//节点中添加了button组件 则可以添加click事件监听
leftBtnNode.on('click', () => {
if (!this._cantouch) {
return;
}
if (this.curPage == 0) {
return;
}
this.curPage = 0
this.leftMove();
// 游戏结束时需要调用这个方法通知系统作业完成
onHomeworkFinish();
cc.audioEngine.play(this.audioBtn.clip, false, 0.8)
})
const rightBtnNode = bottomPart.getChildByName('btn_right');
//节点中添加了button组件 则可以添加click事件监听
rightBtnNode.on('click', () => {
if (!this._cantouch) {
return;
}
if (this.curPage == 1) {
return;
}
this.curPage = 1
this.rightMove();
cc.audioEngine.play(this.audioBtn.clip, false, 0.5)
})
},
leftMove() {
this._cantouch = false;
const len = this.pic1.parent.width;
cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX }, { easing: 'cubicInOut' })
.start();
cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
},
rightMove() {
this._cantouch = false;
const len = this.pic1.parent.width;
cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX - len }, { easing: 'cubicInOut' })
.start();
cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX - len }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
},
// update (dt) {},
// ------------------------------------------------
getSprNode(resName) {
const sf = cc.find('Canvas/res/img/' + resName).getComponent(cc.Sprite).spriteFrame;
const node = new cc.Node();
node.addComponent(cc.Sprite).spriteFrame = sf;
return node;
},
getSpriteFrimeByUrl(url, cb) {
cc.loader.load({ url }, (err, img) => {
const spriteFrame = new cc.SpriteFrame(img)
if (cb) {
cb(spriteFrame);
}
})
},
getSprNodeByUrl(url, cb) {
const node = new cc.Node();
const spr = node.addComponent(cc.Sprite);
this.getSpriteFrimeByUrl(url, (sf) => {
spr.spriteFrame = sf;
if (cb) {
cb(node);
}
})
},
playAudioByUrl(audio_url, cb = null) {
if (audio_url) {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
if (cb) {
cc.audioEngine.setFinishCallback(audioId, () => {
cb();
});
}
});
}
},
// ------------------------------------------
});
export const defaultData = {
"pic_url": "http://staging-teach.cdn.ireadabc.com/ed94332a503c31e0908bd4c6923a2665.png",
"pic_url_2": "http://staging-teach.cdn.ireadabc.com/5fb60317ade0195d35ad8034d5370a7f.png",
"text": "This is a test label.",
"audio_url": "http://staging-teach.cdn.ireadabc.com/f47f1d7b5c160fe1c59500d180346240.mp3"
}
\ No newline at end of file
This diff is collapsed.
export function getPosByAngle(angle, len) {
const radian = angle * Math.PI / 180;
const x = Math.sin(radian) * len;
const y = Math.cos(radian) * len;
return { x, y };
}
export function getAngleByPos(px, py, mx, my) {
const x = Math.abs(px - mx);
const y = Math.abs(py - my);
const z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
const cos = y / z;
const radina = Math.acos(cos); // 用反三角函数求弧度
let angle = Math.floor(180 / (Math.PI / radina) * 100) / 100; // 将弧度转换成角度
if (mx > px && my > py) {// 鼠标在第四象限
angle = 180 - angle;
}
if (mx === px && my > py) {// 鼠标在y轴负方向上
angle = 180;
}
if (mx > px && my === py) {// 鼠标在x轴正方向上
angle = 90;
}
if (mx < px && my > py) {// 鼠标在第三象限
angle = 180 + angle;
}
if (mx < px && my === py) {// 鼠标在x轴负方向
angle = 270;
}
if (mx < px && my < py) {// 鼠标在第二象限
angle = 360 - angle;
}
// console.log('angle: ', angle);
return angle;
}
export function exchangeNodePos(baseNode, targetNode) {
return baseNode.convertToNodeSpaceAR(targetNode._parent.convertToWorldSpaceAR(cc.v2(targetNode.x, targetNode.y)));
}
export function RandomInt(a, b = 0) {
let max = Math.max(a, b);
let min = Math.min(a, b);
return Math.floor(Math.random() * (max - min) + min);
}
export function randomSortByArr(arr) {
const newArr = [];
const tmpArr = arr.concat();
while (tmpArr.length > 0) {
const randomIndex = Math.floor(tmpArr.length * Math.random());
newArr.push(tmpArr[randomIndex]);
tmpArr.splice(randomIndex, 1);
}
return newArr;
}
export function setSprNodeMaxLen(sprNode, maxW, maxH) {
const sx = maxW / sprNode.width;
const sy = maxH / sprNode.height;
const s = Math.min(sx, sy);
sprNode.scale = Math.round(s * 1000) / 1000;
}
export function localPosTolocalPos(baseNode, targetNode) {
const worldPos = targetNode.parent.convertToWorldSpaceAR(cc.v2(targetNode.x, targetNode.y));
const localPos = baseNode.parent.convertToNodeSpaceAR(cc.v2(worldPos.x, worldPos.y));
return localPos;
}
export function worldPosToLocalPos(worldPos, baseNode) {
const localPos = baseNode.parent.convertToNodeSpaceAR(cc.v2(worldPos.x, worldPos.y));
return localPos;
}
export function getScaleRateBy2Node(baseNode, targetNode, maxFlag = true) {
const worldRect1 = targetNode.getBoundingBoxToWorld();
const worldRect2 = baseNode.getBoundingBoxToWorld();
const sx = worldRect1.width / worldRect2.width;
const sy = worldRect1.height / worldRect2.height;
if (maxFlag) {
return Math.max(sx, sy);
} else {
return Math.min(sx, sy);
}
}
export function getDistance (start, end){
var pos = cc.v2(start.x - end.x, start.y - end.y);
var dis = Math.sqrt(pos.x*pos.x + pos.y*pos.y);
return dis;
}
export function playAudioByUrl(audio_url, cb=null) {
if (audio_url) {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
if (cb) {
cc.audioEngine.setFinishCallback(audioId, () => {
cb();
});
}
});
}
}
export function btnClickAnima(btn, time=0.15, rate=1.05) {
btn.tmpScale = btn.scale;
btn.on(cc.Node.EventType.TOUCH_START, () => {
cc.tween(btn)
.to(time / 2, {scale: btn.scale * rate})
.start()
})
btn.on(cc.Node.EventType.TOUCH_CANCEL, () => {
cc.tween(btn)
.to(time / 2, {scale: btn.tmpScale})
.start()
})
btn.on(cc.Node.EventType.TOUCH_END, () => {
cc.tween(btn)
.to(time / 2, {scale: btn.tmpScale})
.start()
})
}
export function getSpriteFrimeByUrl(url, cb) {
cc.loader.load({ url }, (err, img) => {
const spriteFrame = new cc.SpriteFrame(img)
if (cb) {
cb(spriteFrame);
}
})
}
export function getSprNode(resName) {
const sf = cc.find('Canvas/res/img/' + resName).getComponent(cc.Sprite).spriteFrame;
const node = new cc.Node();
node.addComponent(cc.Sprite).spriteFrame = sf;
return node;
}
export function getSprNodeByUrl(url, cb) {
const node = new cc.Node();
const spr = node.addComponent(cc.Sprite);
getSpriteFrimeByUrl(url, (sf) => {
spr.spriteFrame = sf;
if (cb) {
cb(spr);
}
})
}
export function playAudio(audioClip, cb = null) {
if (audioClip) {
const audioId = cc.audioEngine.playEffect(audioClip, false, 0.8);
if (cb) {
cc.audioEngine.setFinishCallback(audioId, () => {
cb();
});
}
}
}
export async function asyncDelay(time) {
return new Promise((resolve, reject) => {
try {
setTimeout(() => {
resolve();
}, time * 1000);
} catch (e) {
reject(e);
}
})
}
export class FireworkSettings {
baseNode; // 父节点
nodeList; // 火花节点的array
pos; // 发射点
side; // 发射方向
range; // 扩散范围
number; // 发射数量
scalseRange; // 缩放范围
constructor(baseNode, nodeList,
pos = cc.v2(0, 0),
side = cc.v2(0, 100),
range = 50,
number = 100,
scalseRange = 0
) {
this.baseNode = baseNode;
this.nodeList = nodeList;
this.pos = pos;
this.side = side;
this.range = range;
this.number = number;
this.scalseRange = scalseRange;
}
static copy(firework) {
return new FireworkSettings(
firework.baseNode,
firework.nodeList,
firework.pos,
firework.side,
firework.range,
firework.number,
);
}
}
export async function showFireworks(fireworkSettings) {
const { baseNode, nodeList, pos, side, range, number, scalseRange } = fireworkSettings;
new Array(number).fill(' ').forEach(async (_, i) => {
let rabbonNode = new cc.Node();
rabbonNode.parent = baseNode;
rabbonNode.x = pos.x;
rabbonNode.y = pos.y;
rabbonNode.angle = 60 * Math.random() - 30;
let node = cc.instantiate(nodeList[RandomInt(nodeList.length)]);
node.parent = rabbonNode;
node.active = true;
node.x = 0;
node.y = 0;
node.angle = 0;
node.scale = (Math.random() - 0.5) * scalseRange + 1;
const rate = Math.random();
const angle = Math.PI * (Math.random() * 2 - 1);
await asyncTweenBy(rabbonNode, 0.3, {
x: side.x * rate + Math.cos(angle) * range * rate,
y: side.y * rate + Math.sin(angle) * range * rate
}, {
easing: 'quadIn'
});
cc.tween(rabbonNode)
.by(8, { y: -2000 })
.start();
cc.tween(rabbonNode)
.to(5, { scale: (Math.random() - 0.5) * scalseRange + 1 })
.start();
rabbonFall(rabbonNode);
await asyncDelay(Math.random());
cc.tween(node)
.by(0.15, { x: -10, angle: -10 })
.by(0.3, { x: 20, angle: 20 })
.by(0.15, { x: -10, angle: -10 })
.union()
.repeatForever()
.start();
cc.tween(rabbonNode)
.delay(5)
.to(0.3, { opacity: 0 })
.call(() => {
node.stopAllActions();
node.active = false;
node.parent = null;
node = null;
})
.start();
});
}
async function rabbonFall(node) {
const time = 1 + Math.random();
const offsetX = RandomInt(-200, 200) * time;
await asyncTweenBy(node, time, { x: offsetX, angle: offsetX * 60 / 200 });
rabbonFall(node);
}
export async function asyncTweenTo(node, duration, obj, ease = undefined) {
return new Promise((resolve, reject) => {
try {
cc.tween(node)
.to(duration, obj, ease)
.call(() => {
resolve();
})
.start();
} catch (e) {
reject(e);
}
});
}
export async function asyncTweenBy(node, duration, obj, ease = undefined) {
return new Promise((resolve, reject) => {
try {
cc.tween(node)
.by(duration, obj, ease)
.call(() => {
resolve();
})
.start();
} catch (e) {
reject(e);
}
});
}
export function showTrebleFirework(baseNode, rabbonList) {
const middle = new FireworkSettings(baseNode, rabbonList);
middle.pos = cc.v2(0, -400);
middle.side = cc.v2(0, 1000);
middle.range = 200;
middle.number = 100;
middle.scalseRange = 0.4;
const left = FireworkSettings.copy(middle);
left.pos = cc.v2(-600, -400);
left.side = cc.v2(200, 1000);
const right = FireworkSettings.copy(middle);
right.pos = cc.v2(600, -400);
right.side = cc.v2(-200, 1000);
showFireworks(middle);
showFireworks(left);
showFireworks(right);
}
export function onHomeworkFinish() {
const middleLayer = cc.find('middleLayer');
if (middleLayer) {
const middleLayerComponent = middleLayer.getComponent('middleLayer');
if (middleLayerComponent.role == 'student') {
middleLayerComponent.onHomeworkFinish(() => { });
}
} else {
console.log('onHomeworkFinish');
}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "35e7895d-d54a-4940-840f-e7ec5d397aca",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "f0680ae0-c079-45ef-abd7-9e63d90b982b",
"uuid": "1da4a1eb-1b7f-4c66-b682-afb2bb2c25f8",
"downloadMode": 0,
"duration": 0.130612,
"duration": 0.141083,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "897db934-b5dd-4d83-b482-45c92812366e",
"downloadMode": 0,
"duration": 4.179592,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "6c4277af-aebb-470b-bce6-5215a5edee90",
"downloadMode": 0,
"duration": 1.688,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "8e061c88-bf21-44e1-8360-13bd6085b2bf",
"downloadMode": 0,
"duration": 1.044898,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "e84b4934-1211-4c2b-86c8-b0cb8ff50ab2",
"downloadMode": 0,
"duration": 0.19325,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "326dee4a-6daf-4748-86a3-acecad20fc07",
"downloadMode": 0,
"duration": 0.20898,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "4cd1a303-1f39-40a3-9127-5afcad88e2af",
"downloadMode": 0,
"duration": 3.343673,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "be885015-b019-4b28-8900-dcb6b18752f3",
"downloadMode": 0,
"duration": 1.3865,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "a9d1d994-0776-4dcf-9bb7-eac5dbee2854",
"downloadMode": 0,
"duration": 3.787755,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "c533d5b8-bf5c-48ce-aa60-ccc7195ec880",
"downloadMode": 0,
"duration": 0.938688,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "24c4d28a-b9c9-4d73-8bd6-bd2101ffba7c",
"downloadMode": 0,
"duration": 0.556563,
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.0.1",
"uuid": "bf718d00-23b5-4393-8285-ef7a241b9afa",
"subMetas": {}
}
\ No newline at end of file
{"name":"正确效果","SubTexture":[{"name":"1/勾","x":1,"height":112,"y":1,"width":128},{"name":"1/星1","x":196,"height":59,"y":72,"width":57},{"name":"1/星2","x":1,"height":45,"y":192,"width":43},{"name":"1/星3","x":131,"height":64,"y":72,"width":63},{"name":"1/星4","x":201,"height":45,"y":1,"width":45},{"name":"1/星6","x":131,"height":69,"y":1,"width":68},{"name":"1/星7","x":1,"height":40,"y":115,"width":37},{"name":"1/星5","x":196,"height":57,"y":133,"width":56},{"name":"1/星8","x":78,"height":33,"y":115,"width":32},{"name":"1/星9","x":40,"height":37,"y":115,"width":36}],"imagePath":"正确效果_tex.png","height":256,"width":256}
\ No newline at end of file
{
"ver": "1.0.1",
"uuid": "2a1c4975-20c7-425f-a159-537a0e44fbcb",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "ff0f9fe1-277f-4d06-9a86-2b838f49e899",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 256,
"height": 256,
"platformSettings": {},
"subMetas": {
"正确效果_tex": {
"ver": "1.0.4",
"uuid": "ef344e8b-5ff7-495c-8441-7891c9963a6f",
"rawTextureUuid": "ff0f9fe1-277f-4d06-9a86-2b838f49e899",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": -1,
"offsetY": 9,
"trimX": 1,
"trimY": 1,
"width": 252,
"height": 236,
"rawWidth": 256,
"rawHeight": 256,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "455577d8-9fe9-451b-8bb0-241ffe3d08ef",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "2.1.0",
"uuid": "ac5cd74f-7311-4fae-a586-f37a87e61455",
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "2.1.0",
"uuid": "ce2d6cce-f4b4-4f14-b57c-f026dc181a88",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.0",
"uuid": "61fcc759-2eb5-4e50-a2f3-0cc3393881d8",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "a777fdf7-eb0b-41df-b0f7-ada8ed99b97d",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.2.9",
"uuid": "c020c4aa-c261-4e24-ae6e-a564a5bb6865",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"readonly": false,
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.1.2",
"uuid": "7488de23-e223-4a1c-9a61-a332a676694e",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
// 全局环境预声明
window.g = window.g || {}; // 全局
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "c41b0e51-55d7-443c-af3a-b22c3dd9b9e5",
"uuid": "a9bcccd1-c2b7-4db1-8744-3c0fcb95b824",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
......
/**
* eff_welldown
*/
var eff_well = cc.Class({
extends: cc.Component,
properties: {
eff_welldown: {
default: null,
type: cc.Animation,
displayName: "撒花特效"
},
},
ctor: function () {
eff_well.inst = this;
g.eff_well = eff_well;
},
//显示特效
showEff: function () {
this.node.active = true;
this.eff_welldown.play();
//播放撒花音效
g.speaker.inst.play_congratulation();
setTimeout(() => {
this.node.active = false;
}, 2000)
}
});
{
"ver": "1.0.8",
"uuid": "ade7af40-d56d-4087-bbc6-2888fef55353",
"uuid": "872df374-a19c-4662-9d3d-1f85329b5d49",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
......
g.utils = {
// 范围随机
randFromTo: function (_min, _max) {
var min = parseFloat(_min);
var max = parseFloat(_max);
return (min + Math.random() * (max - min));
},
// 范围随机一个整数
// 例:1~3,返回的可能值为:1、2、3
randFromTo_Int: function (min, max) {
var val = this.randFromTo(min, max + 1 - 0.0001);
return Math.floor(val);
},
// 深拷贝
deepCopy: function (src) {
var cpy = src instanceof Array ? [] : {};
for (var i in src) {
cpy[i] = typeof src[i] === 'object' ? this.deepCopy(src[i]) : src[i];
}
return cpy;
},
deletList: function (list, val) {
var index = list(val);
if (index > -1) {
this.splice(index, 1);
}
}
}
export function getPosByAngle(angle, len) {
const radian = angle * Math.PI / 180;
const x = Math.sin(radian) * len;
const y = Math.cos(radian) * len;
return { x, y };
}
export function getAngleByPos(px, py, mx, my) {
const x = Math.abs(px - mx);
const y = Math.abs(py - my);
const z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
const cos = y / z;
const radina = Math.acos(cos); // 用反三角函数求弧度
let angle = Math.floor(180 / (Math.PI / radina) * 100) / 100; // 将弧度转换成角度
if (mx > px && my > py) {// 鼠标在第四象限
angle = 180 - angle;
}
if (mx === px && my > py) {// 鼠标在y轴负方向上
angle = 180;
}
if (mx > px && my === py) {// 鼠标在x轴正方向上
angle = 90;
}
if (mx < px && my > py) {// 鼠标在第三象限
angle = 180 + angle;
}
if (mx < px && my === py) {// 鼠标在x轴负方向
angle = 270;
}
if (mx < px && my < py) {// 鼠标在第二象限
angle = 360 - angle;
}
// console.log('angle: ', angle);
return angle;
}
export function exchangeNodePos(baseNode, targetNode) {
return baseNode.convertToNodeSpaceAR(targetNode._parent.convertToWorldSpaceAR(cc.v2(targetNode.x, targetNode.y)));
}
export function RandomInt(a, b = 0) {
let max = Math.max(a, b);
let min = Math.min(a, b);
return Math.floor(Math.random() * (max - min) + min);
}
export function Between(a, b, c) {
return [a, b, c].sort((a, b) => a - b)[1];
}
export function randomSortByArr(arr) {
const newArr = [];
const tmpArr = arr.concat();
while (tmpArr.length > 0) {
const randomIndex = Math.floor(tmpArr.length * Math.random());
newArr.push(tmpArr[randomIndex]);
tmpArr.splice(randomIndex, 1);
}
return newArr;
}
export async function asyncTweenTo(node, duration, obj, ease = undefined) {
return new Promise((resolve, reject) => {
cc.tween(node)
.to(duration, obj, ease)
.call(() => {
resolve();
})
.start();
});
}
export async function asyncTweenBy(node, duration, obj, ease = undefined) {
return new Promise((resolve, reject) => {
cc.tween(node)
.by(duration, obj, ease)
.call(() => {
resolve();
})
.start();
});
}
export async function asyncPlayDragonBoneAnimation(node, animationName, time = 1, onFrameEvent) {
return new Promise((resolve, reject) => {
node.getComponent(dragonBones.ArmatureDisplay)
.once(dragonBones.EventObject.COMPLETE, () => {
resolve();
});
node.getComponent(dragonBones.ArmatureDisplay)
.on(dragonBones.EventObject.FRAME_EVENT, ({ name }) => {
if (onFrameEvent && typeof (onFrameEvent) == 'function') {
onFrameEvent(name);
}
});
node.getComponent(dragonBones.ArmatureDisplay)
.playAnimation(animationName, time);
});
}
export async function asyncPlayEffectByUrl(url, loop = false) {
return new Promise((resolve, reject) => {
cc.assetManager.loadRemote(url, (err, clip) => {
console.log(clip);
cc.audioEngine.playEffect(clip, loop);
resolve();
});
});
}
export async function jelly(node) {
return new Promise((resolve, reject) => {
cc.tween(node)
.to(0.1, { scaleX: 0.9, scaleY: 1.1 })
.to(0.1, { scaleX: 1.1, scaleY: 0.9 })
.to(0.1, { scaleX: 1, scaleY: 1 })
.call(resolve)
.start();
});
}
export async function asyncDelay(time) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, time * 1000);
})
}
export async function showFireworks(baseNode, nodeList, pos = cc.v2(0, 0), side = cc.v2(0, 100), range = 50, number = 100) {
new Array(number).fill(' ').forEach(async (_, i) => {
let rabbonNode = new cc.Node();
rabbonNode.parent = baseNode;
rabbonNode.x = pos.x;
rabbonNode.y = pos.y;
rabbonNode.angle = 60 * Math.random() - 30;
let node = cc.instantiate(nodeList[RandomInt(nodeList.length)]);
node.parent = rabbonNode;
node.active = true;
node.x = 0;
node.y = 0;
node.angle = 0;
const rate = Math.random();
const angle = Math.PI * (Math.random() * 2 - 1);
await asyncTweenBy(rabbonNode, 0.3, {
x: side.x * rate + Math.cos(angle) * range * rate,
y: side.y * rate + Math.sin(angle) * range * rate
}, {
easing: 'quadIn'
});
cc.tween(rabbonNode)
.by(8, { y: -2000 })
.start();
rabbonFall(rabbonNode);
await asyncDelay(Math.random());
cc.tween(node)
.by(0.15, { x: -10, angle: -10 })
.by(0.3, { x: 20, angle: 20 })
.by(0.15, { x: -10, angle: -10 })
.union()
.repeatForever()
.start();
cc.tween(rabbonNode)
.delay(5)
.to(0.3, { opacity: 0 })
.call(() => {
node.stopAllActions();
node.active = false;
node.parent = null;
node = null;
})
.start();
});
}
async function rabbonFall(node) {
const time = 1 + Math.random();
const offsetX = RandomInt(-200, 200) * time;
await asyncTweenBy(node, time, { x: offsetX, angle: offsetX * 60 / 200 });
rabbonFall(node);
}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "f4ede462-f8d7-4069-ba80-915611c058ca",
"uuid": "3cf09c30-536f-42ae-83bb-cbb3c5cd93eb",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
......
/**
* 适配
*/
cc.Class({
extends: cc.Component,
properties: {
UIMax: {
default: [],
type: cc.Node,
displayName: "等比放大"
},
topUI: {
default: [],
type: cc.Widget,
},
bgScaleMax: {
default: [],
type: cc.Node,
displayName: "背景适配"
},
nodeUIOffset: {
default: [],
type: cc.Node,
displayName: "节点偏移"
},
canvasView: {
default: null,
type: cc.Canvas,
displayName: "根节点"
},
isCanvas: {
default: false,
}
},
onLoad: function () { //开启适配
this.widgetList = [];
this.scheduleOnce(function () {
if (!this.isCanvas) {
this.init();
} else {
var canvaSize = this.findCanvas();
var w = (canvaSize.width) / 720;
var h = (canvaSize.height) / 1280;
this.MaxSize = w / h > 1 ? w / h : h / w;
this.setUIMax(this.MaxSize);
this.settopUI(this.MaxSize);
this.setBgScale();
this.setUiPositon();
var scene = cc.director.getScene();
var list = scene.getComponentsInChildren(cc.Widget)
for (var i in list) {
list[i].updateAlignment();
}
}
}, 0);
g.event_mgr.reg("adjustUI", () => {
this.setBgScale();
this.setUiPositon();
});
this.MaxSize = 1;
},
init: function () {
var canvaSize = this.findCanvas();
var diff = canvaSize.width / canvaSize.height;
var bili = 750 / 1334;
if (diff > bili) {
this.canvasView.fitWidth = false;
this.canvasView.fitHeight = true;
} else if (diff < bili) {
this.canvasView.fitWidth = true;
this.canvasView.fitHeight = false;
} else {
this.canvasView.fitWidth = true;
this.canvasView.fitHeight = true;
}
var w = (canvaSize.width) / 750;
var h = (canvaSize.height) / 1334;
this.MaxSize = w / h > 1 ? w / h : h / w;
g.data_mgr.MaxSize = this.MaxSize;
this.setUIMax(this.MaxSize);
this.settopUI(this.MaxSize);
this.setBgScale();
this.setUiPositon();
var scene = cc.director.getScene();
var list = scene.getComponentsInChildren(cc.Widget)
for (var i in list) {
list[i].updateAlignment();
}
},
onDestroy: function () {
g.event_pump.unReg("adjustUI");
},
settopUI: function (s) {
if (!g.data_mgr.phoneInfo) {
return;
}
var top = g.data_mgr.phoneInfo;
top = top * s;
for (var i in this.topUI) {
if (this.topUI[i].perTop == undefined) {
this.topUI[i].perTop = this.topUI[i].top;
} else {
this.topUI[i].top = this.topUI[i].perTop;
}
this.topUI[i].top += top;
console.log(this.topUI[i].top);
}
},
//背景适配
setBgScale: function () {
for (var i in this.bgScaleMax) {
// 1. 先找到 SHOW_ALL 模式适配之后,本节点的实际宽高以及初始缩放值
let scaleForShowAll = Math.min(
cc.view.getCanvasSize().width / this.bgScaleMax[i].width,
cc.view.getCanvasSize().height / this.bgScaleMax[i].height
);
let realWidth = this.bgScaleMax[i].width * scaleForShowAll;
let realHeight = this.bgScaleMax[i].height * scaleForShowAll;
// 2. 基于第一步的数据,再做缩放适配
this.bgScaleMax[i].scale = Math.max(
cc.view.getCanvasSize().width / realWidth,
cc.view.getCanvasSize().height / realHeight
);
}
},
//适配节点位置
setUiPositon: function () {
for (var i in this.nodeUIOffset) {
// 1. 先找到 SHOW_ALL 模式适配之后,本节点的实际宽高以及初始缩放值
let srcScaleForShowAll = Math.min(
cc.view.getCanvasSize().width / 1280,
cc.view.getCanvasSize().height / 720
);
let realWidth = 1280 * srcScaleForShowAll;
let realHeight = 720 * srcScaleForShowAll;
// 2. 基于第一步的数据,再做节点宽高重置
this.nodeUIOffset[i].width = 1280 * (cc.view.getCanvasSize().width / realWidth);
this.nodeUIOffset[i].height = 720 * (cc.view.getCanvasSize().height / realHeight);
}
},
setUIMax: function (size) {
for (var i in this.UIMax) {
if (this.UIMax[i].perScale == undefined) {
this.UIMax[i].perScale = this.UIMax[i].scaleX;
} else {
this.UIMax[i].scaleX = this.UIMax[i].perScale;
this.UIMax[i].scaleY = this.UIMax[i].perScale;
}
this.UIMax[i].scaleX *= size;
this.UIMax[i].scaleY *= size;
}
},
findCanvas: function () {
if (cc.sys.isNative) {
return {
width: cc.view.getFrameSize().width,
height: cc.view.getFrameSize().height
};
} else {
return {
width: cc.game.canvas.clientWidth,
height: cc.game.canvas.clientHeight
};
}
}
});
{
"ver": "1.0.8",
"uuid": "b54300af-b8e5-4b4e-aa2f-9ac1cef7b598",
"isPlugin": true,
"uuid": "0e963fa9-ea21-492e-a9ae-92a33a8c7456",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
......
{
"ver": "1.1.2",
"uuid": "b62d4b1c-d7ed-4c6e-8f1f-f8695a087353",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
var TouchDragger = cc.Class({
extends: cc.Component,
properties: {
MaxHeight: {
default: "",
displayName: "最大高度"
},
MaxWidth: {
default: "",
displayName: "最大宽度"
},
grid: {
default: null,
type: cc.Prefab,
displayName: "格子预制体"
},
hGrid: {
default: "",
displayName: "单个高度"
},
wGrid: {
default: "",
displayName: "单个宽度"
}
},
ctor: function () {
TouchDragger.inst = this;
g.TouchDragger = TouchDragger;
},
onLoad: function () {
this.arMap = [];
this.isEnd = false;
//是否是第一次执行移动
this.isFirstMove = true;
//初始化格子数据
this.initGridInfo(g.data_mgr.challengeData.IngredientList);
},
start: function () {
this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegan, this);
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd, this);
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancel, this);
},
//触摸开始
touchBegan: function (event) {
if (this.isEnd) return;
this.isMove = false;
var posScreen = event.getLocation();//点击事件获取位置
var posNode = this.node.parent.convertToNodeSpaceAR(posScreen);
this.iposBegan = this.getFormatIPos(posNode);
this.iposMove = cc.v2(-1, -1);
if (this.iposBegan.x == -1) return;
var ndBegan = this.arMap[this.iposBegan.y][this.iposBegan.x];
if (!ndBegan.active) {
return;
}
ndBegan.runAction(this.getAction("scale"));
ndBegan.zIndex = 1;
this.deltaPos = ndBegan.x + ndBegan.y;
},
//触摸移动
touchMove: function (event) {
if (this.isEnd || (GodGuide && GodGuide.getTask())) return;
if (this.iposBegan.x == -1) return;
var posScreen = event.getLocation(); //点击事件获取位置
var posNode = this.node.parent.convertToNodeSpaceAR(posScreen);
var iposTouch = this.getFormatIPos(posNode);
if (this.isFirstMove == true) {
this.iposBegan = this.getFormatIPos(posNode);
this.isFirstMove = false;
};
var delta = event.getDelta();
var ndBegan = this.arMap[this.iposBegan.y][this.iposBegan.x];
if (!ndBegan.active) {
return;
}
ndBegan.x += delta.x;
ndBegan.y += delta.y;
var deltaPos = ndBegan.x + ndBegan.y;
if (Math.abs(this.deltaPos - deltaPos) > 10) {
this.isMove = true;
}
this.iposMove = iposTouch;
},
//触摸结束
touchEnd: function (event) {
if (this.isEnd) return;
if (this.iposBegan.x == -1) return;
var ndBegan = this.arMap[this.iposBegan.y][this.iposBegan.x];
if (!ndBegan.active) {
this.isMove = false;
return;
}
if (!this.isMove) {
cc.log("点击了");
ndBegan.stopAllActions();
ndBegan.setScale(1);
ndBegan.runAction(cc.moveTo(0.1, this.getGridOriginPos(this.iposBegan)));
ndBegan.callback && ndBegan.callback();
return
}
this.isFirstMove = true;
this.arMap[this.iposBegan.y][this.iposBegan.x].zIndex = 0;
if (this.iposBegan.x == -1 || this.iposMove.x >= 0 && this.iposMove.y >= 0) {
ndBegan.stopAllActions();
ndBegan.setScale(1);
ndBegan.runAction(cc.moveTo(0.1, this.getGridOriginPos(this.iposMove)));
if (this.iposMove.x != -1) {
var ndMove = this.arMap[this.iposMove.y][this.iposMove.x];
ndMove.stopAllActions();
ndMove.runAction(cc.moveTo(0.1, this.getGridOriginPos(this.iposBegan)));
this.arMap[this.iposMove.y][this.iposMove.x] = ndBegan;
this.arMap[this.iposBegan.y][this.iposBegan.x] = ndMove;
}
} else {
ndBegan.stopAllActions();
ndBegan.setScale(1);
ndBegan.runAction(cc.moveTo(0.1, this.getGridOriginPos(this.iposBegan)));
if (this.iposMove.x != -1) {
var ndMove = this.arMap[this.iposMove.y][this.iposMove.x];
ndMove.stopAllActions();
ndMove.runAction(cc.moveTo(0.1, this.getGridOriginPos(this.iposMove)));
}
}
this.isMove = false;
},
//触摸取消
touchCancel: function (event) {
this.arMap[this.iposBegan.y][this.iposBegan.x].zIndex = 0;
var ndBegan = this.arMap[this.iposBegan.y][this.iposBegan.x];
ndBegan.stopAllActions();
ndBegan.setScale(1);
ndBegan.runAction(cc.moveTo(0.1, this.getGridOriginPos(this.iposBegan)));
if (this.iposMove.x != -1) {
var ndMove = this.arMap[this.iposMove.y][this.iposMove.x];
ndMove.stopAllActions();
ndMove.runAction(cc.moveTo(0.1, this.getGridOriginPos(this.iposMove)));
}
this.isMove = false;
},
//初始化格子数据
initGridInfo: function (list) {
for (var i = this.MaxHeight - 1; i >= 0; --i) {
this.arMap[i] = [];
for (var j = 0; j < this.MaxWidth; ++j) {
var ndGrid = cc.instantiate(this.grid);
ndGrid.parent = this.node;
//获得节点的位置
ndGrid.position = this.getGridOriginPos(cc.v2(j, i));
this.arMap[i][j] = ndGrid;
// ndGrid.getComponent("grid").updateUI(3, 30);
var num = (this.MaxHeight - i - 1) * this.MaxWidth + j;
ndGrid.active = list[num] != undefined;
ndGrid.getComponent("grid").updateUI(list[num], 0);
}
}
},
//获得动作
getAction: function (name) {
if (name === "scale") {
return cc.repeatForever(cc.sequence(cc.scaleTo(0.15, 1.3)
, cc.scaleTo(0.3, 1)));
}
else if (name === "rotate") {
return cc.repeatForever(cc.sequence(cc.rotateBy(0.15, 30), cc.rotateBy(0.3, -60), cc.rotateBy(0.15, 30)));
}
return null;
},
//获得直角坐标
getFormatIPos: function (pos) {
var ipos = cc.v2(Math.floor((pos.x - this.node.x) / this.wGrid), Math.floor((pos.y - this.node.y) / this.hGrid));
if (ipos.x < 0 || ipos.x >= this.MaxWidth || ipos.y < 0 || ipos.y >= this.MaxHeight) {
ipos.x = -1;
}
return ipos;
},
//获得格子起始坐标
getGridOriginPos: function (ipos) {
return cc.v2(10 + (ipos.x + 0.5) * this.wGrid, 10 + (ipos.y + 0.5) * this.hGrid);
},
});
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "ccc66642-cf0e-4b1b-ae3d-c4b18f4fe53a",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
/**
* 游戏主逻辑
*/
var game = cc.Class({
extends: cc.Component,
properties: {
Item_0: {
default: null,
type: cc.Node,
displayName: "空节点"
},
Item_1: {
default: null,
type: cc.Node,
displayName: "预制体"
},
contentArr: {
default: null,
type: cc.Node,
displayName: "底下内容"
},
contentArr_1: {
default: [],
type: cc.Node,
displayName: "目标位置"
},
// btnList: {
// default: [],
// type: cc.Button,
// displayName: "上下页"
// },
mask_node: {
default: null,
type: cc.Node,
displayName: "遮罩"
}
},
ctor: function () {
game.inst = this;
g.game = game;
},
// 生命周期 onLoad
onLoad() {
//初始化游戏
this.initGame();
if (window.addEventListener) {
window.addEventListener('resize', this.scaleEventCallBack, false)
} else if (window.attachEvent) {
window.attachEvent('resize', this.scaleEventCallBack, false)
}
},
//屏幕缩放
scaleEventCallBack: function () {
g.event_mgr.send("adjustUI");
},
//初始化游戏
initGame: function () {
//重置游戏数据游戏数据
g.data_mgr.resGameData();
//获得数据
g.res_mgr.getFormData();
let rec1 = new cc.Rect(10, 10, 100, 50);//声明矩形区域
},
setAABB(Id) {
var node = this.contentArr_1[Id]
let svLeftBottomPoint = node.parent.convertToWorldSpaceAR(
cc.v2(
node.x - node.anchorX * node.width / 2,
node.y - node.anchorY * node.height / 2
)
);
// 求出 ScrollView 可视区域在世界坐标系中的矩形(碰撞盒)
let svBBoxRect = cc.rect(
svLeftBottomPoint.x - 60,
svLeftBottomPoint.y - 30,
node.width,
node.height
);
// console.log(Id + ":" + svLeftBottomPoint.x + "," + svLeftBottomPoint.y);
return svBBoxRect
},
//检查当前缩放倍数
checkScale: function (num) {
var scale = 1;
if (num > 2 && num <= 4) {
scale = 0.74
}
if (num > 4) {
scale = 0.65
}
return scale;
},
//添加节点
addItem2: function (Info) {
for (var i = 0; i < 30; i++) {
//for (var i = 0; i < Info.length; i++) {
let newItem_0 = cc.instantiate(this.Item_0);
let newItem_1 = cc.instantiate(this.Item_1);
//更新子项
//var com = newItem.getComponent("item");
//com.updateUI(Info[i]);
//newItem.scale = this.checkScale(Info.length);
//newItem.y = 0;
newItem_1.active = true;
newItem_1.type = 1;
newItem_1.parent = newItem_0;
newItem_0.parent = this.contentArr;
// if (i == 1 && Info.length == 2) {
// newItem.parent = this.contentArr[2];
// this.contentArr[2].active = true;
// //this.contentArr[2].height *= this.checkScale(Info.length);
// }
// else {
// var num_1 = Math.ceil((i + 1) / 2) - 1;
// newItem.parent = this.contentArr[num_1]
// this.contentArr[num_1].active = true;
// this.contentArr[num_1].height == 300 && (this.contentArr[num_1].height = this.contentArr[num_1].height * this.checkScale(Info.length));
// }
};
},
//更新界面信息
UpdataUi: function () {
//获得当前页的关卡
var itemInfo = g.data_mgr.getPageInfo();
//第几排的第几个来算这个位置
this.resetUI();
//添加项
this.addItem2(itemInfo);
// //设置上下页按钮状态
// this.setButtonState();
},
//重置UI界面
resetUI: function () {
// //移除所有子节点
// this.contentArr.removeAllChildren();
// //移除所有子节点
// this.contentArr_1[0].removeAllChildren();
// //移除所有子节点
// this.contentArr_1[1].removeAllChildren();
},
//播放音乐
PlayAudio: function () {
//获得播放路径
var path = g.data_mgr.getPlayUrl();
g.res_mgr.playAudioByUrl(path, (url) => {
g.snd_mgr.playEffect(url);
});
},
//游戏开始
gameStart: function () {
console.log("游戏开始:" + g.data_mgr);
//播放一个上面的音乐
this.setAudioInfo(1);
},
//设置上下页按钮状态
setButtonState: function () {
//先判断题目长度
if (g.data_mgr.data.contentObj.pageArr.length < 2) {
this.btnList[0].node.active = false;
this.btnList[1].node.active = false;
} else {
//如果第一页
if (g.data_mgr.pageId == 0) {
this.btnList[1].node.active = true;
this.btnList[0].node.active = false;
}
if (g.data_mgr.pageId == g.data_mgr.data.contentObj.pageArr.length - 1) {
this.btnList[0].node.active = true;
this.btnList[1].node.active = false;
}
if (g.data_mgr.pageId > 0 && g.data_mgr.pageId < g.data_mgr.data.contentObj.pageArr.length - 1) {
this.btnList[0].node.active = true;
this.btnList[1].node.active = true;
}
}
},
//上一关
onBtnLastPage: function () {
g.speaker.inst.play_btn();
if (g.data_mgr.pageId - 1 >= 0) {
g.data_mgr.pageId -= 1;
this.setButtonState();
this.onBtnReStart();
}
},
//下一关
onBtnNextPage: function () {
g.speaker.inst.play_btn();
if (g.data_mgr.pageId + 1 < g.data_mgr.data.contentObj.pageArr.length) {
g.data_mgr.pageId += 1;
this.setButtonState();
this.onBtnReStart();
}
},
//重新开始
onBtnReStart: function () {
g.speaker.inst.play_btn();
//移除所有计时器
this.unscheduleAllCallbacks();
//初始化界面
this.UpdataUi();
g.speaker.inst.play_restart();
},
onBtnMask: function () {
if (this.isLoadEnd) {
this.isLoadEnd = false;
g.speaker.inst.play_start(() => {
setTimeout(() => {
g.game.inst.playAudioTitle(() => {
g.game.inst.mask_node.active = false;
//游戏开始
g.game.inst.gameStart();
});
}, 500)
});
}
},
});
{
"ver": "1.0.8",
"uuid": "8b0b794c-7f5e-4e94-82b8-d1c85bc69eb8",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
/**
* item
*/
cc.Class({
extends: cc.Component,
properties: {
Item_name: {
default: null,
type: cc.Label,
displayName: "名字"
},
Item_photo: {
default: null,
type: cc.Node,
displayName: "图片"
},
},
start: function () {
this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegan, this);
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd, this);
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancel, this);
},
//触摸开始
touchBegan: function (event) {
this.isMove = false;
this.deltaPos = this.node.x + this.node.y;
// this.node.parent = g.game.inst.temp_contentArr;
},
//触摸移动
touchMove: function (event) {
var posScreen = event.getLocation(); //点击事件获取位置
var posNode = this.node.parent.convertToNodeSpaceAR(posScreen);
// var iposTouch = this.getFormatIPos(posNode);
var delta = event.getDelta();
this.node.x += delta.x;
this.node.y += delta.y;
var deltaPos = this.node.x + this.node.y;
if (Math.abs(this.deltaPos - deltaPos) > 10) {
this.isMove = true;
}
var contentArrPos = g.game.inst.setAABB(1);
var contentArrPos_0 = g.game.inst.setAABB(0);
// 获取 ScrollView Node 的左下角坐标在世界坐标系中的坐标
let svLeftBottomPoint = this.node.parent.convertToWorldSpaceAR(
cc.v2(
this.node.x - this.node.anchorX * this.node.width,
this.node.y - this.node.anchorY * this.node.height
)
);
// 求出 ScrollView 可视区域在世界坐标系中的矩形(碰撞盒)
var posNode_1 = cc.rect(
svLeftBottomPoint.x,
svLeftBottomPoint.y,
this.node.width,
this.node.height
);
var isIntersect_1 = contentArrPos.containsRect(posNode_1);//判断是否被包含
var isIntersect_2 = contentArrPos_0.containsRect(posNode_1);
// console.log("坐标" + svLeftBottomPoint.x + "," + svLeftBottomPoint.y + "是否包含" + isIntersect_1);
if (isIntersect_1) {
console.log("被1包含" + isIntersect_1);
}
if (isIntersect_2) {
console.log("被2包含" + isIntersect_2);
}
},
//触摸结束
touchEnd: function (event) {
//获得世界坐标
var posScreen = event.getLocation(); //点击事件获取位置
var posNode = this.node.convertToNodeSpaceAR(posScreen);
console.log("世界坐标" + posNode);
if (!this.isMove) {
cc.log("点击了");
this.onBtnRotate();
//回到原来的位置
this.node.x = 0;
this.node.y = 0;
return
}
//获得俩个节点的世界坐标
var contentArrPos_0 = g.game.inst.setAABB(0);
var contentArrPos_1 = g.game.inst.setAABB(1);
// 获取 ScrollView Node 的左下角坐标在世界坐标系中的坐标
let svLeftBottomPoint = this.node.parent.convertToWorldSpaceAR(
cc.v2(
this.node.x - this.node.anchorX * this.node.width,
this.node.y - this.node.anchorY * this.node.height
)
);
// 求出 ScrollView 可视区域在世界坐标系中的矩形(碰撞盒)
var posNode_1 = cc.rect(
svLeftBottomPoint.x,
svLeftBottomPoint.y,
this.node.width,
this.node.height
);
var isIntersect_1 = contentArrPos_1.containsRect(posNode_1);//判断是否被包含
var isIntersect_0 = contentArrPos_0.containsRect(posNode_1);
// console.log("坐标" + svLeftBottomPoint.x + "," + svLeftBottomPoint.y + "是否包含" + isIntersect_1);
if (isIntersect_1) {
if (this.node.type == 1) {
g.speaker.inst.play_good();
g.game.inst.contentArr_1[1].getChildByName("db").active = true;
g.game.inst.contentArr_1[1].getChildByName("db").getComponent(dragonBones.ArmatureDisplay).playAnimation("newAnimation", 1);
this.node.parent = g.game.inst.contentArr_1[1].getChildByName("connent_3").getChildByName("Layout");
}
else {
g.speaker.inst.play_error();
this.node.getChildByName("red").active = true;
setTimeout(() => {
this.node.getChildByName("red").active = false;
//回到原来的位置
this.node.x = 0;
this.node.y = 0;
}, 1000)
}
console.log("被1包含" + isIntersect_1);
} else
if (isIntersect_0) {
if (this.node.type == 2) {
g.speaker.inst.play_good();
g.game.inst.contentArr_1[0].getChildByName("db").active = true;
g.game.inst.contentArr_1[0].getChildByName("db").getComponent(dragonBones.ArmatureDisplay).playAnimation("newAnimation", 1);
this.node.parent = g.game.inst.contentArr_1[0].getChildByName("connent_3").getChildByName("Layout");
console.log("被2包含" + isIntersect_0);
}
else {
g.speaker.inst.play_error();
this.node.getChildByName("red").active = true;
setTimeout(() => {
this.node.getChildByName("red").active = false;
//回到原来的位置
this.node.x = 0;
this.node.y = 0;
}, 1000)
}
}
else {
//回到原来的位置
this.node.x = 0;
this.node.y = 0;
}
},
//触摸取消
touchCancel: function (event) {
//回到原来的位置
this.node.x = 0;
this.node.y = 0;
this.isMove = false;
},
//更新界面ui
updateUI: function (Info) {
//当前数据
this.itemInfo = Info;
//初始化数据
this.InitData();
},
//点击翻面
onBtnRotate: function () {
cc.tween(this.node)
.to(0.3, { scaleX: 0 })
.call(() => {
if (this.Item_name.node.active) {
this.Item_name.node.active = false;
this.Item_photo.active = true;
} else {
this.Item_name.node.active = true;
this.Item_photo.active = false;
}
})
.to(0.3, { scaleX: 1 })
.start();
},
//初始化信息
InitData: function () {
this.eff_window[0].scaleX = 1;
this.eff_window[1].scaleX = 1;
},
//图片适配
photoScare: function (node, type) {
var maxNum = type == 1 ? 160 : 190;
let maxSize = Math.min(maxNum / node.height, maxNum / node.width);
if (node.perScale == undefined) {
node.perScale = node.scaleX;
} else {
node.scaleX = node.perScale;
node.scaleY = node.perScale;
}
node.scaleX *= maxSize;
node.scaleY *= maxSize;
},
});
{
"ver": "1.0.8",
"uuid": "e729b387-9d1a-47a4-9d3d-076fd1ddc360",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
/**
* 音效
*/
var speaker = cc.Class({
extends: cc.Component,
properties: {
eff_btn: {
default: null,
type: cc.AudioClip,
displayName: "点击音效"
},
eff_congratulation: {
default: null,
type: cc.AudioClip,
displayName: "撒花音效"
},
eff_error: {
default: null,
type: cc.AudioClip,
displayName: "点击错误音效"
},
eff_good: {
default: null,
type: cc.AudioClip,
displayName: "点击正确音效"
},
eff_showPop: {
default: null,
type: cc.AudioClip,
displayName: "显示弹窗音效"
},
eff_start: {
default: null,
type: cc.AudioClip,
displayName: "游戏开始音效"
},
eff_open: {
default: null,
type: cc.AudioClip,
displayName: "拉开窗帘"
},
eff_restart: {
default: null,
type: cc.AudioClip,
displayName: "重新开始"
},
},
ctor: function () {
speaker.inst = this;
g.speaker = speaker;
},
//点击按钮
play_btn: function () {
g.snd_mgr.playEffect(this.eff_btn);
},
//撒花音效
play_congratulation: function () {
g.snd_mgr.playEffect(this.eff_congratulation);
},
//答错
play_error: function () {
g.snd_mgr.playEffect(this.eff_error);
},
//答对
play_good: function (cb) {
g.snd_mgr.playEffect(this.eff_good, cb);
},
//显示弹窗
play_showPop: function () {
g.snd_mgr.playEffect(this.eff_showPop);
},
//游戏开始
play_start: function (cb) {
g.snd_mgr.playEffect(this.eff_start, cb);
},
//拉开窗帘
play_open: function () {
g.snd_mgr.playEffect(this.eff_open);
},
//重新开始
play_restart: function () {
g.snd_mgr.playEffect(this.eff_restart);
},
});
{
"ver": "1.0.8",
"uuid": "ab52071c-b063-4dc5-8f90-7b771a4d0e68",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "739e697c-eeb0-400c-b62d-7d1da103d577",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
/**
* 数据管理器
*/
g.data_mgr = {
playId: null,//播放id
playType: null,//播放类型
temPlayAudio: [],//临时的播放列表
data: null,//表所有数据
pageId: 0,//页id
dragonName: null,//龙骨动画名字
lineColor: ['#2AFF51', '#FF0000', '#FF51E0', '#E5FB31', '#43DFEF', '#FFC788', ' #FFFFFF', ' #FF7474'],//线的颜色
_imageResList: [],//图片资源列表
_audioResList: [],//音频资源列表
_animaResList: [],//动画资源列表
//获得默认数据
getDefaultData() {
const dataJson = {
"contentObj": {
"pageArr": [{
"pageInfo": [
{ "colorList": "1", "fontSize": 50, "fontList": "1,3", "groupLabel": "I saw a purple #11plentpp #00sdfasdf on the #10sky on the sky", "groupPic": "", "group_audio_url": "http://staging-teach.cdn.ireadabc.com/bfcd329e246551615375ce0788fc397e.mp3" }, { "groupLabel": "I saw a purple #11plent on the sky #00on the sky", "groupPic": "http://staging-teach.cdn.ireadabc.com/2d349cf780b1fcec761a2350936183f0.png", "group_audio_url": "" }, { "groupLabel": "33#013#103#003", "groupPic": "http://staging-teach.cdn.ireadabc.com/2d349cf780b1fcec761a2350936183f0.png", "group_audio_url": "http://staging-teach.cdn.ireadabc.com/bfcd329e246551615375ce0788fc397e.mp3" }, { "groupLabel": "", "groupPic": "https://adsfs.heytapimage.com/ads-material-depot/image/9db677f693622128668326572dd8d6d2.jpg", "group_audio_url": "http://staging-teach.cdn.ireadabc.com/bfcd329e246551615375ce0788fc397e.mp3" }, { "groupLabel": "", "groupPic": "", "group_audio_url": "http://staging-teach.cdn.ireadabc.com/bfcd329e246551615375ce0788fc397e.mp3" }]
}, {
"pageInfo": [
{ "groupLabel": "22222", "groupPic": "http://staging-teach.cdn.ireadabc.com/2d349cf780b1fcec761a2350936183f0.png", "group_audio_url": "http://staging-teach.cdn.ireadabc.com/bfcd329e246551615375ce0788fc397e.mp3" }, { "groupLabel": "33333", "groupPic": "http://staging-teach.cdn.ireadabc.com/2d349cf780b1fcec761a2350936183f0.png", "group_audio_url": "http://staging-teach.cdn.ireadabc.com/bfcd329e246551615375ce0788fc397e.mp3" }, { "groupLabel": "11111", "groupPic": "http://staging-teach.cdn.ireadabc.com/2d349cf780b1fcec761a2350936183f0.png", "group_audio_url": "http://staging-teach.cdn.ireadabc.com/bfcd329e246551615375ce0788fc397e.mp3" }, { "groupLabel": "11111", "groupPic": "http://staging-teach.cdn.ireadabc.com/2d349cf780b1fcec761a2350936183f0.png", "group_audio_url": "http://staging-teach.cdn.ireadabc.com/bfcd329e246551615375ce0788fc397e.mp3" }]
}]
}
}
const data = dataJson;
// const data = JSON.parse(dataJson);
// const data = [];
return data;
},
//{"contentObj":{"pageArr":[{"pageInfo":[{"a_pic_url":"http://staging-teach.cdn.ireadabc.com/4c987bc8980e235c6b6e2ae9a409cfc1.png","b_pic_url":"http://staging-teach.cdn.ireadabc.com/1ffb03273ae56047adab077dc8cc794c.png","a_audio_url":"","b_audio_url":"","groupLabel":"11111","groupPic":"http://staging-teach.cdn.ireadabc.com/2d349cf780b1fcec761a2350936183f0.png","type":"Image"},{"a_pic_url":"","b_pic_url":"","a_audio_url":"","b_audio_url":"","groupLabel":"a","groupPic":"" ,"type":"Spine","ske_json":"http://staging-teach.cdn.ireadabc.com/e48564e39f64ef92dee4309b3493652a.json","ske_json_name":"mao_ske.json","tex_json":"http://staging-teach.cdn.ireadabc.com/233b2f102f321086b70c239a1bd4ba1a.json","tex_json_name":"mao_tex.json","tex_png":"http://staging-teach.cdn.ireadabc.com/d5c00d0cf339484801dc235ed33200d0.png","tex_png_name":"mao_tex.png"}]},{"pageInfo":[]},{"pageInfo":[{"a_pic_url":"","b_pic_url":"","a_audio_url":"","b_audio_url":"","groupLabel":"","groupPic":"","type":"Spine","uploadData":"","uploadUrl":"","ske_json":"http://staging-teach.cdn.ireadabc.com/e48564e39f64ef92dee4309b3493652a.json","ske_json_name":"mao_ske.json"}]}],"title":"16516510","audio_url":"http://staging-teach.cdn.ireadabc.com/bfcd329e246551615375ce0788fc397e.mp3"},"type":"Image"}
//重置数据
resGameData() {
this._imageResList = [];
this._audioResList = [];
this._animaResList = [];
this.temPlayAudio = [];
},
//获得播放路径
getPlayUrl: function () {
for (var i in this._audioResList) {
var audioInfo = this._audioResList[i];
if (this.playId == audioInfo.typeId && this.playType == audioInfo.positionId) {
return audioInfo.url;
}
}
},
//获取当前整页数据
getPageInfo: function () {
return this.data.contentObj.pageArr[this.pageId].pageInfo;
},
//获得整条数据
getResultInfo: function (id) {
var pageInfo = this.data.contentObj.pageArr[this.pageId].pageInfo;
return pageInfo[id];
},
//获得图片信息 type 1上面,type 2下面
getImgInfo: function (type) {
var list = [];
for (var i in g.data_mgr._imageResList) {
var imgList = g.data_mgr._imageResList[i];
if (imgList.positionId == type) {
list.push(imgList)
}
}
return list;
},
//处理数据
proGameData: function () {
// this.addPreloadImage();
// this.addPreloadAudio();
// this.addPreloadAnima();
this.preload();
console.log("数据处理完毕:");
},
//预加载图片
addPreloadImage() {
//btnState 0正常显示,1显示成功,2显示灰色,3连线完成
var pageInfo = this.data.contentObj.pageArr[this.pageId].pageInfo;
for (var i in pageInfo) {
this._imageResList.push({ url: pageInfo[i].groupPic, typeId: i });
}
},
//预加载声音
addPreloadAudio() {
var pageInfo = this.data.contentObj.pageArr[this.pageId].pageInfo;
for (var i in pageInfo) {
this._audioResList.push({ url: pageInfo[i].a_audio_url, typeId: i, positionId: 1, isPlay: false });
this._audioResList.push({ url: pageInfo[i].b_audio_url, typeId: i, positionId: 2, isPlay: false });
this.temPlayAudio.push(i);
}
},
addPreloadAnima() {
},
preload() {
const preloadArr = this._imageResList.concat(this._audioResList).concat(this._animaResList);
cc.assetManager.loadAny(preloadArr, null, null, (err, data) => {
//结束回调
this.loadEnd();
if (window && window["air"]) {
window["air"].hideAirClassLoading();
}
cc.debug.setDisplayStats(false);
});
},
loadEnd() {
//更新游戏界面信息
g.game.inst.UpdataUi();
g.game.inst.isLoadEnd = true;
},
}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "91e03520-a8ad-4317-a914-1850e6e64926",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// 事件汞
let eventList = {}; // 响应列表(元素结构:eventName,[[target:cb]])
g.event_mgr = {
// 注册事件-响应 入参:事件名、响应、目标名
reg: function (eventName, cb, target) {
var event = eventList[eventName];
if (!event) {
event = eventList[eventName] = {};
}
event[target] = cb;
},
// 注销事件-响应 入参:事件名、目标名
unReg: function (eventName, target) {
var event = eventList[eventName];
if (event) {
if (event[target]) {
event[target] = null;
}
}
},
unRegName: function (eventName) {
eventList[eventName] = {};
},
// 广播事件 入参:事件名、参数
send: function (eventName, params) {
var event = eventList[eventName];
if (event) {
for (var target in event) {
var cb = event[target];
if (cb) {
cb(params);
}
}
}
},
getReglist: function () {
return eventList;
}
};
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "b8bf01c9-341f-4994-91ea-ff45a2f9d150",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// localStorage封装
g.local_storage = {
// 背景音乐音量
getMusicVolume: function () {
var vol = cc.sys.localStorage.getItem("music");
return vol;
},
setMusicVolume: function (vol) {
cc.sys.localStorage.setItem('music', vol)
},
// 音效音量
getEffectsVolume: function () {
var vol = cc.sys.localStorage.getItem("effect");
return vol;
},
setEffectsVolume: function (vol) {
cc.sys.localStorage.setItem('effect', vol);
},
};
{
"ver": "1.0.8",
"uuid": "0d515142-090e-49ac-aea8-19c7b34f8cb4",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
/**
* 资源管理器
*/
g.res_mgr = {
//获得表数据数据
getFormData() {
console.log('初始化数据');
try {
window.courseware.getData((res) => {
//存入数据管理器
g.data_mgr.data = res;
//数据处理
g.data_mgr.proGameData();
console.log("获得表单数据:" + res);
});
} catch (error) {
//console.error('没有查找到courseware.getData方法', error);
//获得默认数据
g.data_mgr.data = g.data_mgr.getDefaultData();
//数据处理
g.data_mgr.proGameData();
}
},
//得到图片资源
getSpriteFrimeByUrl(url, cb) {
cc.assetManager.loadRemote(url, cc.SpriteFrame, (e, sp) => {
const spriteFrame = new cc.SpriteFrame(sp)
cb && cb(spriteFrame);
});
},
playAudioByUrl(audio_url, cb) {
if (audio_url) {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
cb && cb(audioClip);
});
}
},
//加载龙骨
loadSpine(animationDisplay, Info) {
if (Info.type == 'Image') {
return;
}
cc.assetManager.loadAny([{ url: Info.tex_json, ext: '.txt' }, { url: Info.ske_json, ext: '.txt' }], (error, assets) => {
if (error) {
console.log(error)
}
else {
cc.assetManager.loadRemote(Info.tex_png, (error, texture) => {
if (error) {
console.log(error)
}
else {
var atlas = new dragonBones.DragonBonesAtlasAsset();
atlas._uuid = Info.tex_json;
atlas.atlasJson = assets[0];
atlas.texture = texture;
var asset = new dragonBones.DragonBonesAsset();
asset._uuid = Info.ske_json;
asset.dragonBonesJson = assets[1];
animationDisplay.dragonAtlasAsset = atlas;
animationDisplay.dragonAsset = asset;
let data = asset._dragonBonesJsonData.armature[0];
if (!data) {
return;
}
animationDisplay.armatureName = data.name;
g.data_mgr.dragonName = data.animation[0].name;
animationDisplay.node.active = true;
}
});
}
});
},
}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "7121d1fd-fef5-46f9-ae16-ffc9aa7f5e16",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// 声音管理器
g.snd_mgr = {
bgmId: -1, // 背景音乐的音频ID
effIds: [], // 音效的音频ID列表(由cc.audioEngine保证音频ID不重复)
bgmVol: 1, // 背景音乐音量
neweffId: null, //保存上一个音效ID
effVol: 1, // 音效音量
pausebgVol: 1,
pauseeffVol: 1,
sndNativeUrls: {},
newsnd: null,
init: function () {
var local_storage = g.local_storage;
var music_vol = local_storage.getMusicVolume();
var effect_vol = local_storage.getEffectsVolume();
music_vol != undefined && music_vol + "" != "" && this.setMusicVolume(music_vol);
effect_vol != undefined && effect_vol + "" != "" && this.setEffectsVolume(effect_vol);
},
delAudId: function (id) {
if (id == this.bgmId) {
this.bgmId = -1;
return;
}
for (var i = 0; i < this.effIds.length; ++i) {
if (this.effIds[i] == id) {
this.effIds.splice(i, 1);
return;
}
}
},
playMusic: function (snd, _loop, finishCB) {
if (!snd) return;
this.newsnd = snd;
var loop = _loop ? false : true; // 除非指定为false,否则默认为true
// if (g.configs.platform == "vo") {
// this.bgmId = cc.audioEngine.play(snd, loop);
// return;
// }
this.bgmId = cc.audioEngine.playMusic(snd, loop);
// 播放完成回调
if (finishCB) {
cc.audioEngine.setFinishCallback(this.bgmId, function () {
finishCB();
});
}
},
playEffect: function (snd, finishCB) {
if (!snd || this.effVol == 0) return;
var id = cc.audioEngine.playEffect(snd, false); // 音效限定不能重复播放
this.playaudioEffect(id, finishCB);
},
//播放音效
playaudioEffect: function (id, finishCB) {
var self = this;
this.neweffId = id;
this.effIds.push(id);
// 播放完记得删ID
cc.audioEngine.setFinishCallback(id, function () {
self.delAudId(id);
finishCB && finishCB();
});
},
pauseVolume: function () {
cc.audioEngine.stopAll();
},
resumeVolume: function () {
if (this.newsnd != null) {
cc.audioEngine.playMusic(this.newsnd)
}
},
setMusicVolume: function (percent) {
this.bgmVol = percent;
cc.audioEngine.setMusicVolume(~~percent);
},
setEffectsVolume: function (percent) {
this.effVol = percent;
cc.audioEngine.setEffectsVolume(~~percent);
cc.audioEngine.setMusicVolume(~~this.bgmVol);
},
};
\ No newline at end of file
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