Commit c31c6268 authored by 李帅's avatar 李帅

优化

parent 85d52699
/* /*
* @Author: ls * @Author: ls
* @Date: 2022-05-15 18:22:18 * @Date: 2022-05-15 18:22:18
* @LastEditTime: 2022-05-22 17:37:44 * @LastEditTime: 2022-05-22 19:21:58
* @LastEditors: ls * @LastEditors: ls
* @Description: * @Description:
* @FilePath: \ls_gramophone\assets\ls_gramophone\scene\ls_gramophone.ts * @FilePath: \ls_gramophone\assets\ls_gramophone\scene\ls_gramophone.ts
*/ */
import Item from '../script/Item'; import Item from '../script/Item';
import { MyCocosSceneComponent } from '../script/MyCocosSceneComponent'; import { MyCocosSceneComponent } from '../script/MyCocosSceneComponent';
import { onHomeworkFinish } from '../script/util';
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -179,7 +180,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -179,7 +180,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
record_stop.active = true; record_stop.active = true;
this._recording = true; this._recording = true;
// window['Recorder'].start();
if (window['courseware']) {
window['courseware'].startRecord(1);
}
}); });
record_stop.on('click', () => { record_stop.on('click', () => {
this.playLocalAudio('btn'); this.playLocalAudio('btn');
...@@ -189,20 +193,43 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -189,20 +193,43 @@ export default class SceneComponent extends MyCocosSceneComponent {
record_stop.active = false; record_stop.active = false;
this._recording = false; this._recording = false;
// window['Recorder'].stop();
let idx = -1; // 获取当前录制下标
for (let index = 0; index < this.content.childrenCount; index++) { for (let index = 0; index < this.content.childrenCount; index++) {
const element = this.content.children[index]; const element = this.content.children[index];
// 正在录制中 // 正在录制中
if (element.getComponent(Item).getRecording()) { if (element.getComponent(Item).getRecording()) {
element.getComponent(Item).recorded(); idx = index;
break;
}
}
if (window['courseware']) {
window['courseware'].stopRecord((res) => {
this.log('--------录音返回结果 stopRecord ------------');
this.log(res);
this.log(`录音的音频URL是${JSON.parse(res).audioUrl}`);
if (idx !== -1) {
this.content.children[idx].getComponent(Item).recorded();
}
this._records[index] = '';
// this._records[index] = window['Recorder'].getBlob();
this.resetRecord(); this.resetRecord();
return;
if (res && JSON.parse(res).audioUrl) {
if (idx !== -1) {
this._records[idx] = JSON.parse(res).audioUrl;
onHomeworkFinish(res);
}
}
});
} else {
if (idx !== -1) {
this.content.children[idx].getComponent(Item).recorded();
} }
this.resetRecord();
} }
}); });
} }
......
export function getPosByAngle(angle, len) { export function getPosByAngle(angle, len) {
const radian = (angle * Math.PI) / 180;
const radian = angle * Math.PI / 180;
const x = Math.sin(radian) * len; const x = Math.sin(radian) * len;
const y = Math.cos(radian) * len; const y = Math.cos(radian) * len;
return { x, y }; return { x, y };
} }
export function getAngleByPos(px, py, mx, my) { export function getAngleByPos(px, py, mx, my) {
const x = Math.abs(px - mx); const x = Math.abs(px - mx);
const y = Math.abs(py - my); const y = Math.abs(py - my);
const z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); const z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
const cos = y / z; const cos = y / z;
const radina = Math.acos(cos); // 用反三角函数求弧度 const radina = Math.acos(cos); // 用反三角函数求弧度
let angle = Math.floor(180 / (Math.PI / radina) * 100) / 100; // 将弧度转换成角度 let angle = Math.floor((180 / (Math.PI / radina)) * 100) / 100; // 将弧度转换成角度
if (mx > px && my > py) {// 鼠标在第四象限 if (mx > px && my > py) {
// 鼠标在第四象限
angle = 180 - angle; angle = 180 - angle;
} }
if (mx === px && my > py) {// 鼠标在y轴负方向上 if (mx === px && my > py) {
// 鼠标在y轴负方向上
angle = 180; angle = 180;
} }
if (mx > px && my === py) {// 鼠标在x轴正方向上 if (mx > px && my === py) {
// 鼠标在x轴正方向上
angle = 90; angle = 90;
} }
if (mx < px && my > py) {// 鼠标在第三象限 if (mx < px && my > py) {
// 鼠标在第三象限
angle = 180 + angle; angle = 180 + angle;
} }
if (mx < px && my === py) {// 鼠标在x轴负方向 if (mx < px && my === py) {
// 鼠标在x轴负方向
angle = 270; angle = 270;
} }
if (mx < px && my < py) {// 鼠标在第二象限 if (mx < px && my < py) {
// 鼠标在第二象限
angle = 360 - angle; angle = 360 - angle;
} }
// console.log('angle: ', angle); // console.log('angle: ', angle);
return angle; return angle;
} }
export function exchangeNodePos(baseNode, targetNode) { export function exchangeNodePos(baseNode, targetNode) {
...@@ -94,13 +96,13 @@ export function getScaleRateBy2Node(baseNode, targetNode, maxFlag = true) { ...@@ -94,13 +96,13 @@ export function getScaleRateBy2Node(baseNode, targetNode, maxFlag = true) {
} }
} }
export function getDistance (start, end){ export function getDistance(start, end) {
var pos = cc.v2(start.x - end.x, start.y - end.y); var pos = cc.v2(start.x - end.x, start.y - end.y);
var dis = Math.sqrt(pos.x*pos.x + pos.y*pos.y); var dis = Math.sqrt(pos.x * pos.x + pos.y * pos.y);
return dis; return dis;
} }
export function playAudioByUrl(audio_url, cb=null) { export function playAudioByUrl(audio_url, cb = null) {
if (audio_url) { if (audio_url) {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => { cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
const audioId = cc.audioEngine.play(audioClip, false, 0.8); const audioId = cc.audioEngine.play(audioClip, false, 0.8);
...@@ -113,34 +115,32 @@ export function playAudioByUrl(audio_url, cb=null) { ...@@ -113,34 +115,32 @@ export function playAudioByUrl(audio_url, cb=null) {
} }
} }
export function btnClickAnima(btn, time = 0.15, rate = 1.05) {
export function btnClickAnima(btn, time=0.15, rate=1.05) {
btn.tmpScale = btn.scale; btn.tmpScale = btn.scale;
btn.on(cc.Node.EventType.TOUCH_START, () => { btn.on(cc.Node.EventType.TOUCH_START, () => {
cc.tween(btn) cc.tween(btn)
.to(time / 2, {scale: btn.scale * rate}) .to(time / 2, { scale: btn.scale * rate })
.start() .start();
}) });
btn.on(cc.Node.EventType.TOUCH_CANCEL, () => { btn.on(cc.Node.EventType.TOUCH_CANCEL, () => {
cc.tween(btn) cc.tween(btn)
.to(time / 2, {scale: btn.tmpScale}) .to(time / 2, { scale: btn.tmpScale })
.start() .start();
}) });
btn.on(cc.Node.EventType.TOUCH_END, () => { btn.on(cc.Node.EventType.TOUCH_END, () => {
cc.tween(btn) cc.tween(btn)
.to(time / 2, {scale: btn.tmpScale}) .to(time / 2, { scale: btn.tmpScale })
.start() .start();
}) });
} }
export function getSpriteFrimeByUrl(url, cb) { export function getSpriteFrimeByUrl(url, cb) {
cc.loader.load({ url }, (err, img) => { cc.loader.load({ url }, (err, img) => {
const spriteFrame = new cc.SpriteFrame(img) const spriteFrame = new cc.SpriteFrame(img);
if (cb) { if (cb) {
cb(spriteFrame); cb(spriteFrame);
} }
}) });
} }
export function getSprNode(resName) { export function getSprNode(resName) {
...@@ -158,11 +158,9 @@ export function getSprNodeByUrl(url, cb) { ...@@ -158,11 +158,9 @@ export function getSprNodeByUrl(url, cb) {
if (cb) { if (cb) {
cb(spr); cb(spr);
} }
}) });
} }
export function playAudio(audioClip, cb = null) { export function playAudio(audioClip, cb = null) {
if (audioClip) { if (audioClip) {
const audioId = cc.audioEngine.playEffect(audioClip, false); const audioId = cc.audioEngine.playEffect(audioClip, false);
...@@ -179,20 +177,18 @@ export async function asyncDelay(time) { ...@@ -179,20 +177,18 @@ export async function asyncDelay(time) {
try { try {
cc.tween(cc.find('Canvas')) cc.tween(cc.find('Canvas'))
.delay(time) .delay(time)
.call(()=>{ .call(() => {
resolve(null); resolve(null);
}) })
.start(); .start();
} catch (e) { } catch (e) {
reject(e); reject(e);
} }
}) });
} }
export async function asyncLoadDragonBoneAnime(node, { skeJsonData: { url: skeJsonDataUrl }, texJsonData: { url: texJsonDataUrl }, texPngData: { url: texPngDataUrl } }) { export async function asyncLoadDragonBoneAnime(node, { skeJsonData: { url: skeJsonDataUrl }, texJsonData: { url: texJsonDataUrl }, texPngData: { url: texPngDataUrl } }) {
if (!texPngDataUrl || !texJsonDataUrl || !texPngDataUrl || texPngDataUrl == '' || texJsonDataUrl == '' || texPngDataUrl == '') {
if (!texPngDataUrl || !texJsonDataUrl || !texPngDataUrl
|| texPngDataUrl == '' || texJsonDataUrl == '' || texPngDataUrl == '') {
return; return;
} }
...@@ -246,7 +242,7 @@ export async function asyncLoadDragonBoneAnime(node, { skeJsonData: { url: skeJs ...@@ -246,7 +242,7 @@ export async function asyncLoadDragonBoneAnime(node, { skeJsonData: { url: skeJs
dragonDisplay.dragonAtlasAsset = atlas; dragonDisplay.dragonAtlasAsset = atlas;
dragonDisplay.dragonAsset = asset; dragonDisplay.dragonAsset = asset;
let armatureNames = dragonBonesJson.armature.map(data => data.name); let armatureNames = dragonBonesJson.armature.map((data) => data.name);
if (armatureNames.length > 0) { if (armatureNames.length > 0) {
dragonDisplay.armatureName = armatureNames[0]; dragonDisplay.armatureName = armatureNames[0];
...@@ -264,13 +260,7 @@ export class FireworkSettings { ...@@ -264,13 +260,7 @@ export class FireworkSettings {
range; // 扩散范围 range; // 扩散范围
number; // 发射数量 number; // 发射数量
scalseRange; // 缩放范围 scalseRange; // 缩放范围
constructor(baseNode, nodeList, constructor(baseNode, nodeList, pos = cc.v2(0, 0), side = cc.v2(0, 100), range = 50, number = 100, scalseRange = 0) {
pos = cc.v2(0, 0),
side = cc.v2(0, 100),
range = 50,
number = 100,
scalseRange = 0
) {
this.baseNode = baseNode; this.baseNode = baseNode;
this.nodeList = nodeList; this.nodeList = nodeList;
this.pos = pos; this.pos = pos;
...@@ -281,21 +271,13 @@ export class FireworkSettings { ...@@ -281,21 +271,13 @@ export class FireworkSettings {
} }
static copy(firework) { static copy(firework) {
return new FireworkSettings( return new FireworkSettings(firework.baseNode, firework.nodeList, firework.pos, firework.side, firework.range, firework.number);
firework.baseNode,
firework.nodeList,
firework.pos,
firework.side,
firework.range,
firework.number,
);
} }
} }
export async function showFireworks(fireworkSettings) { export async function showFireworks(fireworkSettings) {
const { baseNode, nodeList, pos, side, range, number, scalseRange } = fireworkSettings; const { baseNode, nodeList, pos, side, range, number, scalseRange } = fireworkSettings;
new Array(number).fill(' ').forEach(async (_, i) => { new Array(number).fill(' ').forEach(async (_, i) => {
let rabbonNode = new cc.Node(); let rabbonNode = new cc.Node();
rabbonNode.parent = baseNode; rabbonNode.parent = baseNode;
rabbonNode.x = pos.x; rabbonNode.x = pos.x;
...@@ -313,16 +295,19 @@ export async function showFireworks(fireworkSettings) { ...@@ -313,16 +295,19 @@ export async function showFireworks(fireworkSettings) {
const rate = Math.random(); const rate = Math.random();
const angle = Math.PI * (Math.random() * 2 - 1); const angle = Math.PI * (Math.random() * 2 - 1);
await asyncTweenBy(rabbonNode, 0.3, { await asyncTweenBy(
rabbonNode,
0.3,
{
x: side.x * rate + Math.cos(angle) * range * rate, x: side.x * rate + Math.cos(angle) * range * rate,
y: side.y * rate + Math.sin(angle) * range * rate y: side.y * rate + Math.sin(angle) * range * rate,
}, { },
easing: 'quadIn' {
}); easing: 'quadIn',
},
);
cc.tween(rabbonNode) cc.tween(rabbonNode).by(8, { y: -2000 }).start();
.by(8, { y: -2000 })
.start();
cc.tween(rabbonNode) cc.tween(rabbonNode)
.to(5, { scale: (Math.random() - 0.5) * scalseRange + 1 }) .to(5, { scale: (Math.random() - 0.5) * scalseRange + 1 })
...@@ -331,13 +316,7 @@ export async function showFireworks(fireworkSettings) { ...@@ -331,13 +316,7 @@ export async function showFireworks(fireworkSettings) {
rabbonFall(rabbonNode); rabbonFall(rabbonNode);
await asyncDelay(Math.random()); await asyncDelay(Math.random());
cc.tween(node) 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();
.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) cc.tween(rabbonNode)
.delay(5) .delay(5)
...@@ -355,11 +334,10 @@ export async function showFireworks(fireworkSettings) { ...@@ -355,11 +334,10 @@ export async function showFireworks(fireworkSettings) {
async function rabbonFall(node) { async function rabbonFall(node) {
const time = 1 + Math.random(); const time = 1 + Math.random();
const offsetX = RandomInt(-200, 200) * time; const offsetX = RandomInt(-200, 200) * time;
await asyncTweenBy(node, time, { x: offsetX, angle: offsetX * 60 / 200 }); await asyncTweenBy(node, time, { x: offsetX, angle: (offsetX * 60) / 200 });
rabbonFall(node); rabbonFall(node);
} }
export async function asyncTweenTo(node, duration, obj, ease = undefined) { export async function asyncTweenTo(node, duration, obj, ease = undefined) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
...@@ -411,12 +389,24 @@ export function showTrebleFirework(baseNode, rabbonList) { ...@@ -411,12 +389,24 @@ export function showTrebleFirework(baseNode, rabbonList) {
showFireworks(right); showFireworks(right);
} }
export function onHomeworkFinish() { // 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');
// }
// }
export function onHomeworkFinish(data: any = null) {
const middleLayer = cc.find('middleLayer'); const middleLayer = cc.find('middleLayer');
if (middleLayer) { if (middleLayer) {
const middleLayerComponent = middleLayer.getComponent('middleLayer'); const middleLayerComponent = middleLayer.getComponent('middleLayer');
if (middleLayerComponent.role == 'student') { if (middleLayerComponent.role == 'student') {
middleLayerComponent.onHomeworkFinish(() => { }); middleLayerComponent.onHomeworkFinish(() => {}, data);
} }
} else { } else {
console.log('onHomeworkFinish'); console.log('onHomeworkFinish');
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
"height": 83, "height": 83,
"platformSettings": {}, "platformSettings": {},
"subMetas": { "subMetas": {
"录音": { "icon_record": {
"ver": "1.0.4", "ver": "1.0.4",
"uuid": "5b67343e-8927-4b5f-9653-3aa36a67c245", "uuid": "5b67343e-8927-4b5f-9653-3aa36a67c245",
"rawTextureUuid": "fb73c820-7ca8-4450-8bb6-79d231e5733a", "rawTextureUuid": "fb73c820-7ca8-4450-8bb6-79d231e5733a",
......
{
"ver": "1.1.2",
"uuid": "b9f5800f-8915-4e6e-a914-158e979d6a84",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "53603c71-3077-4b5d-bb59-d6e15e1d3719",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1334,
"height": 750,
"platformSettings": {},
"subMetas": {
"1-点击start开始": {
"ver": "1.0.4",
"uuid": "e10bc390-de9f-45ea-9d83-7e7e4d9421a6",
"rawTextureUuid": "53603c71-3077-4b5d-bb59-d6e15e1d3719",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1334,
"height": 750,
"rawWidth": 1334,
"rawHeight": 750,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "836ecbc5-201b-416e-8eed-5aa0fded9c34",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1334,
"height": 750,
"platformSettings": {},
"subMetas": {
"2-点击左下播放按钮开始播放整段音频内容,再次点击停止播放": {
"ver": "1.0.4",
"uuid": "c1da4ac0-1475-444e-a392-2448afc2ce66",
"rawTextureUuid": "836ecbc5-201b-416e-8eed-5aa0fded9c34",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1334,
"height": 750,
"rawWidth": 1334,
"rawHeight": 750,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "ef0f1593-1e56-4238-93fe-dda41a31dfe6",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1334,
"height": 750,
"platformSettings": {},
"subMetas": {
"3-点击句子播放句子的音频,同时字体颜色变成橘色,句子开头出现播放提示效果": {
"ver": "1.0.4",
"uuid": "e83c8fc3-af7a-43bb-87b3-255ba6ce4724",
"rawTextureUuid": "ef0f1593-1e56-4238-93fe-dda41a31dfe6",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1334,
"height": 750,
"rawWidth": 1334,
"rawHeight": 750,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "e6f3ffd3-f5dd-4a53-a71e-e92e85f3519e",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1334,
"height": 750,
"platformSettings": {},
"subMetas": {
"4-点击句子后面的录音按钮,弹出录音界面,点击start开始录音": {
"ver": "1.0.4",
"uuid": "23555c3e-a82e-4806-a8dd-16e5a0121412",
"rawTextureUuid": "e6f3ffd3-f5dd-4a53-a71e-e92e85f3519e",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1334,
"height": 750,
"rawWidth": 1334,
"rawHeight": 750,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "40eca57e-ea7e-4654-8ea4-828ae552021f",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1334,
"height": 750,
"platformSettings": {},
"subMetas": {
"5-录音结束当前句子后面出现我的录音,点击播放": {
"ver": "1.0.4",
"uuid": "759cf454-75da-48f2-8032-143bec729c24",
"rawTextureUuid": "40eca57e-ea7e-4654-8ea4-828ae552021f",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1334,
"height": 750,
"rawWidth": 1334,
"rawHeight": 750,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "78ac9a51-bbd6-40cb-be04-5ed006163563",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
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