Commit da4df9fd authored by LWD's avatar LWD

代码提交

parent a70e61d2
<div class="model-content"> <div class="model-content">
<div style="width: 300px; margin-top: 15px;">
<div style="padding: 10px;"> <span>点击输入文本内容: </span>
<input type="text" nz-input [(ngModel)]="item.contentObj.title" (blur)="saveItem()">
<div style="width: 300px;" align='center'> </div>
<span>图1: </span>
<app-upload-image-with-preview
[picUrl]="item.pic_url" <div *ngFor="let it of pageArr; let i = index" style="padding: 0.5vw; width: 20%;">
(imageUploaded)="onImageUploadSuccess($event, 'pic_url')"> <div class="border" style="display: flex; align-items: center;">
</app-upload-image-with-preview>
</div> <div class="item-box" style="width:30%">
<div style="width: 20%; padding-left: 20px">
<div style="width: 300px; margin-top: 5px;" align='center'> <h5 style="padding-left: 15px; margin: auto"> 页-{{i+1}}: </h5>
<span>图2: </span>
<app-upload-image-with-preview <div style="display: flex; justify-items: center; align-items: center; height: 40px;">
[picUrl]="item.pic_url_2" <button style="margin-left: 10px;" nz-button nzType="danger" (click)="deletePage(it)">
(imageUploaded)="onImageUploadSuccess($event, 'pic_url_2')"> <span>删除</span>
</app-upload-image-with-preview> </button>
</div> </div>
<div style="width: 300px; margin-top: 15px;"> <div nz-col nzSpan="8" class="add-btn-box">
<span>文本: </span> <button style=" margin: auto; width: 60%; height: 60%;" nz-button nzType="dashed"
<input type="text" nz-input [(ngModel)]="item.text" (blur)="save()"> class="add-btn" (click)="addPic(i)">
</div> <i nz-icon nzType="plus-circle" nzTheme="outline"></i>
add
<div style="margin-top: 5px"> </button>
<span>音频: </span> </div>
<app-audio-recorder </div>
[audioUrl]="item.audio_url" </div>
(audioUploaded)="onAudioUploadSuccess($event, 'audio_url')" </div>
></app-audio-recorder> </div>
</div>
<div nz-col nzSpan="8" class="add-btn-box">
</div> <button style=" margin: auto; width: 60%; height: 60%;" nz-button nzType="dashed" class="add-btn"
(click)="addPage()">
</div> <i nz-icon nzType="plus-circle" nzTheme="outline"></i>
Addpage
</button>
</div>
<div *ngFor="let page of pageArr; let j = index" style="padding: 0.5vw; width: 100%;">
<div *ngFor="let it of page.pageInfo; let i = index" style="padding: 0.5vw; width: 100%;">
<div class="border" style="display: flex; align-items: center;">
<div style="width: 4%">
<h5 style="padding-left: 15px; margin: auto"> 页-{{j+1}}组-{{i+1}}: </h5>
<div style="display: flex; justify-items: center; align-items: center; height: 40px;">
<!--<app-audio-recorder-->
<!--[audioUrl]="it.audio_url"-->
<!--(audioUploaded)="onAudioUploadSuccessByItem($event, it)">-->
<!--</app-audio-recorder>-->
<button style="margin-left: 10px;" nz-button nzType="danger" (click)="deleteItem(it,j)">
<span>删除</span>
<!--<i nz-icon type="close"></i>-->
</button>
</div>
</div>
<!--公共部分-->
<div class="item-box" style="width: 35% ;padding-left: 100px">
<div style="width: 100%;">
<app-upload-image-with-preview style="width: 100%" [picUrl]="it['groupPic']"
(imageUploaded)="onImageUploadSuccessByItem($event, it)">
</app-upload-image-with-preview>
</div>
<input style=" width: 100%; margin-bottom: 0.5vw" type="text" nz-input placeholder="点击输入文本内容"
[(ngModel)]="it.groupLabel" (blur)="saveItem()">
</div>
<div class="item-box" style="width:35%; padding-left: 100px">
<div style="width: 100%;">
<app-upload-image-with-preview [picUrl]="it['a_pic_url']"
(imageUploaded)="onImageUploadSuccessByItem($event, it, 'a')">
</app-upload-image-with-preview>
</div>
<app-audio-recorder style="margin-top: 0.5vw" [audioUrl]="it['a_audio_url']"
(audioUploaded)="onAudioUploadSuccessByItem($event, it, 'a')">
</app-audio-recorder>
</div>
<!--中间部分-->
<div class="item-box" style="width: 35% ;padding-left: 100px">
<div style="width: 100%;">
<app-upload-image-with-preview style="width: 100%" [picUrl]="it['b_pic_url']"
(imageUploaded)="onImageUploadSuccessByItem($event, it, 'b')">
</app-upload-image-with-preview>
</div>
<app-audio-recorder style="margin-top: 0.5vw" [audioUrl]="it['b_audio_url']"
(audioUploaded)="onAudioUploadSuccessByItem($event, it, 'b')">
</app-audio-recorder>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
import { Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef, ChangeDetectorRef } from '@angular/core'; import {
import { JsonPipe } from '@angular/common'; Component,
EventEmitter,
Input,
OnDestroy,
OnChanges,
OnInit,
Output,
ApplicationRef,
ChangeDetectorRef
} from '@angular/core';
@Component({ @Component({
selector: 'app-form', selector: 'app-form',
templateUrl: './form.component.html', templateUrl: './form.component.html',
styleUrls: ['./form.component.css'] styleUrls: ['./form.component.scss']
}) })
export class FormComponent implements OnInit, OnChanges, OnDestroy { export class FormComponent implements OnInit, OnChanges, OnDestroy {
pageArr = [];//页数据
_item: any;
KEY = 'hw_004';
answerType = 'A';
showGuideAudio;
// @Input()
set item(item) {
this._item = item;
// this.init();
}
get item() {
return this._item;
}
@Output()
update = new EventEmitter();
constructor(private appRef: ApplicationRef,
public changeDetectorRef: ChangeDetectorRef) {
}
ngOnInit() {
this.item = {};
this.item.contentObj = {};
const getData = (<any>window).courseware.getData;
getData((data) => {
if (data) {
this.item = data;
} else {
this.item = {};
}
if (!this.item.contentObj) {
this.item.contentObj = {};
}
console.log('~data:', data);
this.init();
this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges();
this.refresh();
}, this.KEY);
// this.initData();
}
ngOnChanges() {
}
ngOnDestroy() {
}
init() {
if (this.item.contentObj.pageArr) {
this.pageArr = this.item.contentObj.pageArr;
} else {
this.pageArr = this.getDefaultPicArr();
this.item.contentObj.pageArr = this.pageArr;
}
this.save();
console.log('item:', this.item);
}
getDefaultPicArr() {
const arr = [];
// for (let i = 0; i < 4; i ++) {
// const data = {};
// data['pic_url'] = '';
//
// const soundArr = [];
// for (let i = 0; i < 3; i++) {
// const tmpData = {};
// tmpData['answer'] = false;
// tmpData['audio_url'] = '';
// soundArr.push(tmpData);
// }
// data['soundArr'] = soundArr;
//
// arr.push(data);
// }
return arr;
}
initData() {
}
deletePage(data) {
const index = this.pageArr.indexOf(data);
if (index !== -1) {
this.pageArr.splice(index, 1);
}
// this.update.emit(this.item);
this.save();
}
deleteItem(data, j) {
const index = this.pageArr[j].pageInfo.indexOf(data);
if (index !== -1) {
this.pageArr[j].pageInfo.splice(index, 1);
}
// this.update.emit(this.item);
this.save();
}
onImageUploadSuccessByItem(e, item, id = null) {
if (id != null) {
item[id + '_pic_url'] = e.url;
} else {
item['groupPic'] = e.url;
}
this.save();
// this.update.emit(this.item);
// console.log('this.item: ', this.item);
}
onAudioUploadSuccessByItem(e, item, id = null) {
if (id != null) {
item[id + '_audio_url'] = e.url;
} else {
item.audio_url = e.url;
}
// this.update.emit(this.item);
this.save();
}
//添加页面
addPage() {
const data = {
pageInfo: []
};
this.pageArr.push(data);
console.log(this.pageArr);
this.saveItem();
}
//添加项进页面
addPic(i) {
const data = {
a_pic_url: '',
b_pic_url: '',
a_audio_url: '',
b_audio_url: '',
groupLabel: '',
groupPic: '',
};
this.pageArr[i].pageInfo.push(data);
console.log(this.pageArr);
this.saveItem();
}
radioClick(it, radioValue) {
it.radioValue = radioValue;
this.saveItem();
}
clickCheckBox() {
console.log(' in clickCheckBox');
this.saveItem();
}
saveItem() {
console.log(' in saveItem');
// this.update.emit(this.item);
this.save();
}
save() {
(<any>window).courseware.setData(this.item, null, this.KEY);
this.refresh();
// 获取数据
const getData = (<any>window).courseware.getData;
getData((data) => {
console.log('data:', data);
}, this.KEY);
}
refresh() {
setTimeout(() => {
this.appRef.tick();
}, 1);
}
guideBtnClick(value) {
this.showGuideAudio = value;
}
}
// 储存数据用
saveKey = "test_001";
// 储存对象
item;
constructor(private appRef: ApplicationRef, private changeDetectorRef: ChangeDetectorRef) {
}
createShell() {
this.item.wordList.push({
word: '',
audio: '',
backWord: '',
backWordAudio: '',
});
this.save();
}
removeShell(idx) {
this.item.wordList.splice(idx, 1);
this.save();
}
ngOnInit() {
this.item = {};
// 获取存储的数据
(<any>window).courseware.getData((data) => {
if (data) {
this.item = data;
}
this.init();
this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges();
this.refresh();
}, this.saveKey);
}
ngOnChanges() {
}
ngOnDestroy() {
}
init() {
}
/**
* 储存图片数据
* @param e
*/
onImageUploadSuccess(e, key) {
this.item[key] = e.url;
this.save();
}
/**
* 储存音频数据
* @param e
*/
onAudioUploadSuccess(e, key) {
this.item[key] = e.url;
this.save();
}
onWordAudioUploadSuccess(e, idx) {
this.item.wordList[idx].audio = e.url;
this.save();
}
onBackWordAudioUploadSuccess(e, idx) {
this.item.wordList[idx].backWordAudio = e.url;
this.save();
}
/**
* 储存数据
*/
save() {
(<any>window).courseware.setData(this.item, null, this.saveKey);
this.refresh();
console.log('this.item = ' + JSON.stringify(this.item));
}
/**
* 刷新 渲染页面
*/
refresh() {
setTimeout(() => {
this.appRef.tick();
}, 1);
}
}
\ No newline at end of file
This diff is collapsed.
import { onHomeworkFinish } from "./util";
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(cb) {
cb(this.getDefaultData());
},
getDefaultData() {
const dataJson = '{"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"}'
const data = JSON.parse(dataJson);
return data;
},
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();
});
}
});
}
},
// ------------------------------------------
});
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(() => { });
}
return;
}
}
\ No newline at end of file
{ {
"ver": "1.1.2", "ver": "1.1.2",
"uuid": "c35bb2f6-f24a-4850-ae44-643f2fdc7541", "uuid": "35e7895d-d54a-4940-840f-e7ec5d397aca",
"isBundle": false, "isBundle": false,
"bundleName": "", "bundleName": "",
"priority": 1, "priority": 1,
......
{
"ver": "1.1.2",
"uuid": "7d25a5d7-a799-4071-8de4-8b430d572289",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{ {
"ver": "2.0.1", "ver": "2.0.1",
"uuid": "f0680ae0-c079-45ef-abd7-9e63d90b982b", "uuid": "1da4a1eb-1b7f-4c66-b682-afb2bb2c25f8",
"downloadMode": 0, "downloadMode": 0,
"duration": 0.130612, "duration": 0.261224,
"subMetas": {} "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": "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": "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": "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", "ver": "1.0.8",
"uuid": "ade7af40-d56d-4087-bbc6-2888fef55353", "uuid": "a9bcccd1-c2b7-4db1-8744-3c0fcb95b824",
"isPlugin": false, "isPlugin": false,
"loadPluginInWeb": true, "loadPluginInWeb": true,
"loadPluginInNative": 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", "ver": "1.0.8",
"uuid": "f4ede462-f8d7-4069-ba80-915611c058ca", "uuid": "3cf09c30-536f-42ae-83bb-cbb3c5cd93eb",
"isPlugin": false, "isPlugin": false,
"loadPluginInWeb": true, "loadPluginInWeb": true,
"loadPluginInNative": true, "loadPluginInNative": true,
......
/**
* 适配
*/
cc.Class({
extends: cc.Component,
properties: {
UIMax: {
default: [],
type: cc.Node,
displayName: "等比放大"
},
topUI: {
default: [],
type: cc.Widget,
},
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);
var scene = cc.director.getScene();
var list = scene.getComponentsInChildren(cc.Widget)
for (var i in list) {
list[i].updateAlignment();
}
}
}, 0);
this.MaxSize = 1;
// if (window.addEventListener) {
// window.addEventListener('resize', scaleEventCallBack, false)
// } else if (window.attachEvent) {
// window.attachEvent('resize', scaleEventCallBack, false)
// };
// g.event_mgr.reg("adjustUI", () => {
// this.init();
// });
},
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);
var scene = cc.director.getScene();
var list = scene.getComponentsInChildren(cc.Widget)
for (var i in list) {
list[i].updateAlignment();
}
},
// //屏幕缩放事件
// scaleEventCallBack: function () {
// //setTimeout(function () {
// g.log("屏幕缩放");
// g.event_mgr.send("adjustUI");
// //}, 500); //延迟0.5秒
// },
onDestroy: function () {
},
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);
}
},
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", "ver": "1.0.8",
"uuid": "b54300af-b8e5-4b4e-aa2f-9ac1cef7b598", "uuid": "0e963fa9-ea21-492e-a9ae-92a33a8c7456",
"isPlugin": true, "isPlugin": false,
"loadPluginInWeb": true, "loadPluginInWeb": true,
"loadPluginInNative": true, "loadPluginInNative": true,
"loadPluginInEditor": false, "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 game = cc.Class({
extends: cc.Component,
properties: {
contentArr_1: {
default: null,
type: cc.Node,
displayName: "内容_1"
},
Item_1: {
default: null,
type: cc.Node,
displayName: "滚动项"
},
contentArr_2: {
default: null,
type: cc.Node,
displayName: "内容_2"
},
Item_2: {
default: null,
type: cc.Node,
displayName: "滚动项"
},
draw: {
default: null,
type: cc.Graphics,
displayName: "滚动项"
},
resultNode: {
default: null,
type: cc.Node,
displayName: "结算弹窗"
}
},
ctor: function () {
game.inst = this;
g.game = game;
},
// 生命周期 onLoad
onLoad() {
//初始化游戏
this.initGame();
},
//初始化游戏
initGame: function () {
//重置游戏数据游戏数据
g.data_mgr.resGameData();
//获得数据
g.res_mgr.getFormData();
//播放游戏开始音效
g.speaker.inst.play_start();
//游戏开始
this.gameStart();
},
//更新界面信息
UpdataUi: function () {
//获得上列表的数据
var topList = g.data_mgr.getImgInfo(1);
var botList = g.data_mgr.getImgInfo(2);
//打乱列表顺序
topList.sort(function () { return Math.random() > 0.5 ? -1 : 1; })
botList.sort(function () { return Math.random() > 0.5 ? -1 : 1; })
this.addItem(topList, this.contentArr_1, this.Item_1, 0);
this.addItem(botList, this.contentArr_2, this.Item_2, 0);
//准备完毕
},
//游戏开始
gameStart: function () {
//播放一个上面的音乐
this.setAudioInfo(1);
this.PlayAudio();
},
//获得随机播放的音乐并播放
setAudioInfo: function (type) {
//随机一个数字 播放这个数字的上段部分
g.data_mgr.temPlayAudio.sort(function () { return Math.random() > 0.5 ? -1 : 1; })
var num = g.data_mgr.temPlayAudio[0];
//设置播放信息
g.data_mgr.playId = num;
g.data_mgr.playType = type;
},
//重新播放音乐
onBtnSound: function () {
this.PlayAudio();
},
//重新开始
onBtnReStart: function () {
//移除所有计时器
this.unscheduleAllCallbacks();
for (var i = 0; i < this.contentArr_1.childrenCount; i++) {
this.contentArr_1.children[i].active = false;
}
for (var i = 0; i < this.contentArr_2.childrenCount; i++) {
this.contentArr_2.children[i].active = false;
}
this.resultNode.active = false;
//初始化界面
this.UpdataUi();
//初始化游戏
this.initGame();
//清除线
this.clearLine();
},
//显示结算弹窗
showResult: function (Info) {
this.resultNode.scale = 0;
this.resultNode.active = true;
cc.tween(this.resultNode)
.to(0.5, { scale: 1 })
.start()
g.result.inst.updateUI(Info);
},
//上一关
onBtnLastPage: function () {
if (g.data_mgr.pageId - 1 >= 0) {
g.data_mgr.pageId -= 1;
this.onBtnReStart();
}
},
//下一关
onBtnNextPage: function () {
if (g.data_mgr.pageId + 1 < g.data_mgr.data.contentObj.pageArr.length) {
g.data_mgr.pageId += 1;
this.onBtnReStart();
}
},
//播放音乐
PlayAudio: function () {
//获得播放路径
var path = g.data_mgr.getPlayUrl();
g.res_mgr.playAudioByUrl(path, (url) => {
g.snd_mgr.playEffect(url);
});
},
//添加项
addItem: function (listInfo, content, item, i) {
if (listInfo.length <= i) {
content.getComponent(cc.Layout).updateLayout();
return;
}
var len = content.childrenCount;
// 添加子项
let newItem = len > i ? content.children[i] : cc.instantiate(item);
// 更新子项
var com = newItem.getComponent("item");
com.updateUI(listInfo[i]);
newItem.active = true;
newItem.parent = content;
this.scheduleOnce(function () {
i += 1;
this.addItem(listInfo, content, item, i)
}.bind(this), 0.01);
},
//点亮 conten:上列表,下列表 state:0 点亮,2变暗
allLightDark(positionId, state) {
var conten = positionId == 1 ? this.contentArr_1 : this.contentArr_2;
for (var i = 0; i < conten.childrenCount; i++) {
var item = conten.children[i]
if (item.state == 1 || item.state == 3) {
continue;
} else {
var com = item.getComponent("item");
//设置状态为可答题
com.setBtnState(state);
}
}
},
ShowLine: function (sx, sy, ex, ey) {
var b = 0;
var a = 0;
var k = ex == sx ? 0 : (ey - sy) / (ex - sx);
if (k == 0) {
a = 0;
b = -5;
} else {
a = k < 0 ? 5 : -5;
}
var difx = sx + a
var dify = sy + k * a + b;
if (ex == sx) {
var difnode = dify > ey;
}
else {
var difnode = ex > sx ? difx < ex : difx > ex;
}
if (difnode) {
this.scheduleOnce(function () {
this.DrawLine(sx, sy, difx, dify);
this.ShowLine(difx, dify, ex, ey);
}.bind(this), 0.01);
}
else {
this.DrawLine(ex, ey, ex, ey);
//移除播放列表的数据
g.data_mgr.temPlayAudio.splice(0, 1);
//显示弹窗
var Info = g.data_mgr.getResultInfo(g.data_mgr.nowNode.typeId);
g.game.inst.showResult(Info);
}
},
//点击测试
DrawLine: function (sx, sy, ex, ey) {
//获得组件
var com = this.draw;
//设置线的颜色
com.strokeColor = new cc.Color().fromHEX(g.data_mgr.lineColor[g.data_mgr.playId]);;
// 设置线条宽度
com.lineWidth = 10;
// 路径起点为0,0
com.moveTo(sx, sy);
// 路径画线到(100,100)
// 路径看不见!!!
com.lineTo(ex, ey);
// 把路径画实,能看见啦!
com.stroke();
},
//
clearLine: function () {
//获得组件
var com = this.draw;
com.clear()
},
});
{
"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: {
Picture: {
default: null,
type: cc.Node,
displayName: "图片"
},
nodeState: {
default: [],
type: cc.Node,
displayName: "节点状态"
},
spt_error: {
default: null,
type: cc.Node,
displayName: "失败"
},
spt_chick: {
default: null,
type: cc.Node,
displayName: "小鸡"
}
},
//更新界面ui
updateUI: function (Info) {
//当前数据
this.itemInfo = Info;
//初始化数据
this.InitData();
//设置图片
this.setPicture(Info.url);
},
//初始化信息
InitData: function () {
//设置按钮状态
this.setBtnState(0);
if (this.itemInfo.positionId == 2) {
this.setBtnState(2);
}
},
//设置图片
setPicture: function (url) {
//图片资源
g.res_mgr.getSpriteFrimeByUrl(url, function (list) {
this.Picture.getComponent(cc.Sprite).spriteFrame = list;
this.Picture.active = true;
}.bind(this));
},
//设置按钮状态
setBtnOpen: function (b) {
this.node.getComponent(cc.Button).enabled = b;
},
//设置按钮状态0可点击 1已答对 2答错 3连线完成
setBtnState: function (num) {
this.nodeState[num].active = true;
switch (~~num) {
case 0:
this.nodeState[0].active = true;
this.nodeState[1].active = false;
this.nodeState[2].active = false;
this.node.state = 0;
this.setBtnOpen(true);
break;
case 1:
this.nodeState[1].active = true;
this.nodeState[2].active = false;
this.node.state = 1;
this.setBtnOpen(false);
break;
case 2:
this.nodeState[1].active = false;
this.nodeState[2].active = true;
this.node.state = 2;
this.setBtnOpen(false);
break;
case 3:
this.nodeState[0].active = true;
this.nodeState[1].active = false;
this.nodeState[2].active = false;
this.node.state = 3;
this.setBtnOpen(false);
break;
}
},
//
onBtnGet: function () {
//如果节点的Id等于当前数据的id的话
if (this.itemInfo.typeId == g.data_mgr.playId && this.itemInfo.positionId == g.data_mgr.playType) {
//播放答对音效
g.speaker.inst.play_good();
this.setBtnState(1);
//如果是上面答对的话
if (this.itemInfo.positionId == 1) {
//执行播放下排的音乐
g.data_mgr.playType = 2;
g.game.inst.PlayAudio();
//设置状态
g.game.inst.allLightDark(1, 2);
g.game.inst.allLightDark(2, 0);
//把这个答对的节点保存起来
g.data_mgr.itemInfo = this.spt_chick;
}
//如果答对的是下排的话
if (this.itemInfo.positionId == 2) {
//连线
var posStart = g.data_mgr.itemInfo.parent.convertToWorldSpaceAR(g.data_mgr.itemInfo.position);
var posEnd = this.spt_chick.parent.convertToWorldSpaceAR(this.spt_chick.position);
g.data_mgr.nowNode = this.itemInfo;
g.game.inst.ShowLine(posStart.x - 640, posStart.y - 360, posEnd.x - 640, posEnd.y - 360);
// //显示弹窗
// var Info = g.data_mgr.getResultInfo(this.itemInfo.typeId);
// g.game.inst.showResult(Info);
//弹窗关闭
// //移除当前播放的音乐
// const index = this.pageArr.indexOf(data);
// if (index !== -1) {
// this.pageArr.splice(index, 1);
// }
}
}
else {
this.spt_error.active = true;
//播放失败音效
g.speaker.inst.play_error();
this.setBtnState(2);
cc.tween(this.spt_error)
.to(0.2, { scale: 1.1 })
.to(0.5, { scale: 0 })
.start()
}
},
});
{
"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
This diff is collapsed.
{
"ver": "1.0.8",
"uuid": "b01b3d2b-07ce-44c5-bd5a-210c686db47c",
"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: "游戏开始音效"
},
},
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 () {
g.snd_mgr.playEffect(this.eff_good);
},
//显示弹窗
play_showPop: function () {
g.snd_mgr.playEffect(this.eff_showPop);
},
//游戏开始
play_start: function () {
g.snd_mgr.playEffect(this.eff_start);
},
});
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