Commit 03da6730 authored by 范雪寒's avatar 范雪寒

feat: 精简

parent 8029fd2d
import { asyncDelay, callMiddleLayerFunction, onHomeworkFinish, playAudio } from "../script/util"; import { asyncDelay, asyncLoadDragonBoneAnime, callMiddleLayerFunction, onHomeworkFinish, playAudio } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent"; import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -13,7 +13,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -13,7 +13,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
addPreloadAudio() { addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源 // TODO 根据自己的配置预加载音频资源
this._audioResList.push({ url: (this.data.lrcData && this.data.lrcData.audio_url) || ''}); this._audioResList.push({ url: (this.data.lrcData && this.data.lrcData.audio_url) || '' });
} }
addPreloadAnima() { addPreloadAnima() {
...@@ -27,8 +27,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -27,8 +27,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
this._animaResList.push({ url: this.data.skeJsonData.url || '' }); this._animaResList.push({ url: this.data.skeJsonData.url || '' });
this._animaResList.push({ url: this.data.texJsonData.url || ''}); this._animaResList.push({ url: this.data.texJsonData.url || '' });
this._animaResList.push({ url: this.data.texPngData.url || ''}); this._animaResList.push({ url: this.data.texPngData.url || '' });
} }
onLoadEnd() { onLoadEnd() {
...@@ -44,8 +44,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -44,8 +44,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
let isAnimLoaded = false; let isAnimLoaded = false;
const checkStart = () => { const checkStart = () => {
console.log( ' in checkStart: ', isDataLoaded) console.log(' in checkStart: ', isDataLoaded)
console.log( ' in isAnimLoaded: ', isAnimLoaded) console.log(' in isAnimLoaded: ', isAnimLoaded)
if (isDataLoaded && isAnimLoaded) { if (isDataLoaded && isAnimLoaded) {
window["air"].hideAirClassLoading(); window["air"].hideAirClassLoading();
...@@ -144,7 +144,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -144,7 +144,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
return; return;
} }
for (let i=0; i<lyrics.length; i++) { for (let i = 0; i < lyrics.length; i++) {
const data = lyrics[i].data; const data = lyrics[i].data;
if (!data) { if (!data) {
...@@ -155,10 +155,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -155,10 +155,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
let duration = 0; let duration = 0;
if (i != lyrics.length - 1) { if (i != lyrics.length - 1) {
duration = lyrics[i+1].time - lyrics[i].time; duration = lyrics[i + 1].time - lyrics[i].time;
} }
this.textArr.push({data, time, duration}); this.textArr.push({ data, time, duration });
} }
} }
...@@ -179,7 +179,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -179,7 +179,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
initView() { initView() {
console.log( ' in initView') console.log(' in initView')
if (this.jumpData) { if (this.jumpData) {
this.junpAnim(); this.junpAnim();
...@@ -216,9 +216,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -216,9 +216,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
let disFrame = maxDisFrame; let disFrame = maxDisFrame;
for (let i=1; i<arr.length; i++) { for (let i = 1; i < arr.length; i++) {
const curDis = (arr[i].text - arr[i-1].text) / 2; const curDis = (arr[i].text - arr[i - 1].text) / 2;
if (disFrame > curDis) { if (disFrame > curDis) {
disFrame = curDis; disFrame = curDis;
} }
...@@ -260,10 +260,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -260,10 +260,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
lightLeft.rotation = 45; lightLeft.rotation = 45;
lightLeft.opacity = 0; lightLeft.opacity = 0;
cc.tween(lightLeft) cc.tween(lightLeft)
.to(1, {rotation: -45}, {easing: "cubicOut"}) .to(1, { rotation: -45 }, { easing: "cubicOut" })
.start(); .start();
cc.tween(lightLeft) cc.tween(lightLeft)
.to(0.5, {opacity: 255}) .to(0.5, { opacity: 255 })
.start(); .start();
const lightRight = this.getSprNode('light'); const lightRight = this.getSprNode('light');
...@@ -276,10 +276,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -276,10 +276,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
lightRight.rotation = -45; lightRight.rotation = -45;
lightRight.opacity = 0; lightRight.opacity = 0;
cc.tween(lightRight) cc.tween(lightRight)
.to(1, {rotation: 45}, {easing: "cubicOut"}) .to(1, { rotation: 45 }, { easing: "cubicOut" })
.start(); .start();
cc.tween(lightRight) cc.tween(lightRight)
.to(0.5, {opacity: 255}) .to(0.5, { opacity: 255 })
.start(); .start();
...@@ -306,7 +306,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -306,7 +306,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.startAudioEnd(); this.startAudioEnd();
})); }));
}) })
.to(1.5, {y: 0}, {easing: "elasticOut"}) .to(1.5, { y: 0 }, { easing: "elasticOut" })
.start(); .start();
this.title = title this.title = title
...@@ -334,13 +334,13 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -334,13 +334,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
sprNode.opacity = 0; sprNode.opacity = 0;
cc.tween(sprNode) cc.tween(sprNode)
.to(time/10, {opacity: 255}) .to(time / 10, { opacity: 255 })
.start(); .start();
cc.tween(sprNode) cc.tween(sprNode)
.to(0.8 * time, {scale: this._mapScaleMin}, {easing: 'elasticOut'}) .to(0.8 * time, { scale: this._mapScaleMin }, { easing: 'elasticOut' })
.delay(0 * time) .delay(0 * time)
.to(0.2 * time, {opacity: 0}) .to(0.2 * time, { opacity: 0 })
.start(); .start();
} }
...@@ -373,9 +373,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -373,9 +373,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
async hideStartView() { async hideStartView() {
const hideSpr = (sprNode, cb=null) => { const hideSpr = (sprNode, cb = null) => {
cc.tween(sprNode) cc.tween(sprNode)
.to(0.3, {opacity: 0}) .to(0.3, { opacity: 0 })
.call(() => { .call(() => {
sprNode.active = false; sprNode.active = false;
cb && cb(); cb && cb();
...@@ -426,7 +426,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -426,7 +426,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
callMiddleLayerFunction('PSQS_jump_to_question', {step: id}, null) callMiddleLayerFunction('PSQS_jump_to_question', { step: id }, null)
return; return;
} }
...@@ -472,7 +472,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -472,7 +472,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
console.log('PSQS_show_rabbit 2') console.log('PSQS_show_rabbit 2')
callMiddleLayerFunction('PSQS_jump_to_question', {step: id}, null) callMiddleLayerFunction('PSQS_jump_to_question', { step: id }, null)
// }) // })
}) })
} }
...@@ -539,7 +539,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -539,7 +539,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
jumpAudio(id) { jumpAudio(id) {
console.log('in jumpAudio id: ', id); console.log('in jumpAudio id: ', id);
const stepData = this.data.stepArr[id-1]; const stepData = this.data.stepArr[id - 1];
console.log('stepData: ', stepData); console.log('stepData: ', stepData);
const time = stepData.text / this.data.frame; const time = stepData.text / this.data.frame;
...@@ -620,13 +620,13 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -620,13 +620,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
back.scale = 0.3; back.scale = 0.3;
back.opacity = 0 back.opacity = 0
cc.tween(back) cc.tween(back)
.to(0.9, {scale: this._mapScaleMin, opacity:255}, {easing: 'elasticOut'}) .to(0.9, { scale: this._mapScaleMin, opacity: 255 }, { easing: 'elasticOut' })
.start(); .start();
back.addComponent(cc.Button); back.addComponent(cc.Button);
back.on('click', () => { back.on('click', () => {
console.log('click back') console.log('click back')
callMiddleLayerFunction('PSQS_exit_book', null, () => {}); callMiddleLayerFunction('PSQS_exit_book', null, () => { });
}) })
} }
...@@ -641,7 +641,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -641,7 +641,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
console.log(' in animPlayEnd 2') console.log(' in animPlayEnd 2')
// setTimeout(() => { // setTimeout(() => {
callMiddleLayerFunction('PSQS_play_animate_over', null, () => {}) callMiddleLayerFunction('PSQS_play_animate_over', null, () => { })
// }, 100); // }, 100);
// callMiddleLayerFunction('PSQS_play_animate_over', this.animaNode, () => {}) // callMiddleLayerFunction('PSQS_play_animate_over', this.animaNode, () => {})
// }) // })
...@@ -684,11 +684,69 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -684,11 +684,69 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
} }
async setOneAnima1(data, cb) {
if (!data.texPngData) {
return
}
asyncLoadDragonBoneAnime(this.canvas, data);
const animaNode = this.canvas.animaNode;
animaNode.scale = this._mapScaleMax;
if (this.data.scale) {
animaNode.scale *= this.data.scale;
}
const dragonDisplay = animaNode.getComponent(dragonBones.ArmatureDisplay);
dragonDisplay.armatureName = dragonDisplay.getArmatureNames()[0];
const animationName = dragonDisplay.getAnimationNames()[0];
dragonDisplay.playAnimation(animationName, 1);
dragonDisplay.timeScale = 0;
dragonDisplay.off(dragonBones.EventObject.FRAME_EVENT)
dragonDisplay.on(dragonBones.EventObject.FRAME_EVENT, (event) => {
console.log(' in frameEventFunc ')
if (this.playTimes > 0) {
this.animChangeStep(event.name);
}
})
dragonDisplay.off(dragonBones.EventObject.COMPLETE)
dragonDisplay.on(dragonBones.EventObject.COMPLETE, () => {
console.log(' in compFunc ')
if (this.isLast && this.playTimes > 0) {
this.showGoodjob();
} else {
this.animPlayEnd();
}
})
animaNode.off('touchstart')
animaNode.on('touchstart', (e) => {
const pos = e.getLocation();
const x = pos.x// - e.currentTarget.width / 2;
const y = pos.y// - e.currentTarget.height / 2;
const newPos = animaNode.convertToNodeSpaceAR(cc.v2(x, y));
console.log('X: ', Math.round(newPos.x));
console.log('Y: ', Math.round(newPos.y));
});
this.dragonDisplay = dragonDisplay;
this.animaNode = animaNode;
cb && cb();
}
dragonDisplay; dragonDisplay;
animaNode; animaNode;
maxTexture; maxTexture;
setOneAnima(data, cb) { setOneAnima(data, cb) {
this.setOneAnima1(data, cb);
return;
console.log(' setOneAnima 1') console.log(' setOneAnima 1')
...@@ -824,14 +882,14 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -824,14 +882,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
// dragonDisplay = animaNode.addComponent(dragonBones.ArmatureDisplay); // dragonDisplay = animaNode.addComponent(dragonBones.ArmatureDisplay);
console.log('dragonDisplay = ' + typeof(dragonDisplay)); console.log('dragonDisplay = ' + typeof (dragonDisplay));
dragonDisplay.dragonAtlasAsset = atlas; dragonDisplay.dragonAtlasAsset = atlas;
console.log('汪汪汪 1') console.log('汪汪汪 1')
dragonDisplay.dragonAsset = asset; dragonDisplay.dragonAsset = asset;
console.log('汪汪汪 2') console.log('汪汪汪 2')
console.log('type: ' + typeof(asset.dragonBonesJson)); console.log('type: ' + typeof (asset.dragonBonesJson));
let json = JSON.parse(asset.dragonBonesJson); let json = JSON.parse(asset.dragonBonesJson);
console.log('json: ', json); console.log('json: ', json);
...@@ -933,8 +991,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -933,8 +991,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
const y = pos.y// - e.currentTarget.height / 2; const y = pos.y// - e.currentTarget.height / 2;
const newPos = animaNode.convertToNodeSpaceAR(cc.v2(x, y)); const newPos = animaNode.convertToNodeSpaceAR(cc.v2(x, y));
console.log('X: ', Math.round( newPos.x )); console.log('X: ', Math.round(newPos.x));
console.log('Y: ', Math.round( newPos.y )); console.log('Y: ', Math.round(newPos.y));
} }
animaNode.off('touchstart') animaNode.off('touchstart')
animaNode.on('touchstart', touchFunc) animaNode.on('touchstart', touchFunc)
...@@ -956,7 +1014,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -956,7 +1014,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
delayRelease(oldAtlas, oldAsset, delteItem=null) { delayRelease(oldAtlas, oldAsset, delteItem = null) {
setTimeout(() => { setTimeout(() => {
...@@ -1008,7 +1066,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1008,7 +1066,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
getCurTextObj() { getCurTextObj() {
const data = this.textArr[this.textArrIndex]; const data = this.textArr[this.textArrIndex];
if (data) { if (data) {
this.textArrIndex ++; this.textArrIndex++;
} }
return data; return data;
} }
...@@ -1040,18 +1098,18 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1040,18 +1098,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.textLabel.node.opacity = 0; this.textLabel.node.opacity = 0;
this.textLabel.string = `<outline color=white width=4>${textObj.data}</outline>` this.textLabel.string = `<outline color=white width=4>${textObj.data}</outline>`
if (textObj.duration ) { if (textObj.duration) {
this.textLabel.curTween = cc.tween(this.textLabel.node) this.textLabel.curTween = cc.tween(this.textLabel.node)
.to(0.2, {opacity: 255}, {easing: 'sineOut'}) .to(0.2, { opacity: 255 }, { easing: 'sineOut' })
.delay(textObj.duration ) .delay(textObj.duration)
.call(() => { .call(() => {
this.curTextObj = null; this.curTextObj = null;
}) })
.to(0.1, {opacity: 0}) .to(0.1, { opacity: 0 })
.start(); .start();
} else { } else {
this.textLabel.curTween = cc.tween(this.textLabel.node) this.textLabel.curTween = cc.tween(this.textLabel.node)
.to(0.2, {opacity: 255}, {easing: 'sineOut'}) .to(0.2, { opacity: 255 }, { easing: 'sineOut' })
.start(); .start();
} }
...@@ -1059,7 +1117,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1059,7 +1117,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
getTextLabel() { getTextLabel() {
const richTextNode = new cc.Node(); const richTextNode = new cc.Node();
richTextNode.y = -this.canvas.height / 2 + 20 * this._mapScaleMin ; richTextNode.y = -this.canvas.height / 2 + 20 * this._mapScaleMin;
richTextNode.opacity = 0; richTextNode.opacity = 0;
richTextNode.anchorY = 0; richTextNode.anchorY = 0;
richTextNode.scale = this._mapScaleMin; richTextNode.scale = this._mapScaleMin;
...@@ -1091,7 +1149,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1091,7 +1149,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
update (dt) { update(dt) {
this.checkShowText(); this.checkShowText();
} }
......
...@@ -238,7 +238,7 @@ export async function asyncLoadDragonBoneAnime(node, { skeJsonData: { url: skeJs ...@@ -238,7 +238,7 @@ export async function asyncLoadDragonBoneAnime(node, { skeJsonData: { url: skeJs
Promise.all([loadTexture, loadTexJsonData, loadSkeJsonData]).then(([texture, atlasJson, dragonBonesJson]) => { Promise.all([loadTexture, loadTexJsonData, loadSkeJsonData]).then(([texture, atlasJson, dragonBonesJson]) => {
const atlas = new dragonBones.DragonBonesAtlasAsset(); const atlas = new dragonBones.DragonBonesAtlasAsset();
atlas.atlasJson = JSON.stringify(atlasJson); atlas.atlasJson = JSON.stringify(atlasJson);
atlas.texture = texture; atlas.texture = <any>texture;
const asset = new dragonBones.DragonBonesAsset(); const asset = new dragonBones.DragonBonesAsset();
asset.dragonBonesJson = JSON.stringify(dragonBonesJson); asset.dragonBonesJson = JSON.stringify(dragonBonesJson);
...@@ -246,7 +246,7 @@ export async function asyncLoadDragonBoneAnime(node, { skeJsonData: { url: skeJs ...@@ -246,7 +246,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 = (<any>dragonBonesJson).armature.map(data => data.name);
if (armatureNames.length > 0) { if (armatureNames.length > 0) {
dragonDisplay.armatureName = armatureNames[0]; dragonDisplay.armatureName = armatureNames[0];
......
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