Commit d6b514d3 authored by 范雪寒's avatar 范雪寒

test

parent 29470d78
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
// Learn life-cycle callbacks: // Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { playAudioByUrl, setSprNodeMaxLen, btnClickAnima } from "../script/util"; import { playAudioByUrl, setSprNodeMaxLen, btnClickAnima, asyncDelay } from "../script/util";
cc.Class({ cc.Class({
extends: cc.Component, extends: cc.Component,
...@@ -965,11 +965,22 @@ cc.Class({ ...@@ -965,11 +965,22 @@ cc.Class({
return; return;
} }
cc.loader.load(image, (error, texture) => { cc.loader.load(image, async (error, texture) => {
cc.loader.load({ url: atlas, type: 'txt' }, (error, atlasJson) => { this.log('error: ' + error);
cc.loader.load({ url: ske, type: 'txt' }, (error, dragonBonesJson) => { await asyncDelay(3);
cc.loader.load({ url: atlas, type: 'txt' }, async (error, atlasJson) => {
this.log('error: ' + error);
await asyncDelay(3);
cc.loader.load({ url: ske, type: 'txt' }, async (error, dragonBonesJson) => {
this.log('error: ' + error);
await asyncDelay(3);
this.log('汪汪汪1'); this.log('汪汪汪1');
await asyncDelay(3);
const atlas = new dragonBones.DragonBonesAtlasAsset(); const atlas = new dragonBones.DragonBonesAtlasAsset();
atlas.atlasJson = atlasJson; atlas.atlasJson = atlasJson;
atlas.texture = texture; atlas.texture = texture;
...@@ -984,13 +995,16 @@ cc.Class({ ...@@ -984,13 +995,16 @@ cc.Class({
let armatures = json["armature"]; let armatures = json["armature"];
// console.log('armatures: ', armatures); // console.log('armatures: ', armatures);
let armatureNames = []; let armatureNames = [];
await asyncDelay(3);
this.log('汪汪汪2'); this.log('汪汪汪2');
for (let i = 0; i < armatures.length; i++) { for (let i = 0; i < armatures.length; i++) {
armatureNames.push(armatures[i].name); armatureNames.push(armatures[i].name);
} }
await asyncDelay(3);
this.log('汪汪汪3'); this.log('汪汪汪3');
// console.log('armatureNames: ', armatureNames); // console.log('armatureNames: ', armatureNames);
if (armatureNames.length > 0) { if (armatureNames.length > 0) {
await asyncDelay(3);
this.log('汪汪汪4'); this.log('汪汪汪4');
let defaultArmatureName = armatureNames[0]; let defaultArmatureName = armatureNames[0];
dragonDisplay.armatureName = defaultArmatureName; dragonDisplay.armatureName = defaultArmatureName;
...@@ -1007,12 +1021,14 @@ cc.Class({ ...@@ -1007,12 +1021,14 @@ cc.Class({
dragonDisplay.playAnimation('normal', -1); dragonDisplay.playAnimation('normal', -1);
dragonDisplay.animaNames = animationNames; dragonDisplay.animaNames = animationNames;
animaNode.y -= 30; animaNode.y -= 30;
await asyncDelay(3);
this.log('汪汪汪5'); this.log('汪汪汪5');
if (animaNode.height) { if (animaNode.height) {
animaNode.scale = 376 / animaNode.height; animaNode.scale = 376 / animaNode.height;
} }
} }
await asyncDelay(3);
this.log('汪汪汪'); this.log('汪汪汪');
}); });
}); });
......
...@@ -71,64 +71,74 @@ export function setSprNodeMaxLen(sprNode, maxW, maxH) { ...@@ -71,64 +71,74 @@ export function setSprNodeMaxLen(sprNode, maxW, maxH) {
} }
export function localPosTolocalPos(baseNode, targetNode) { export function localPosTolocalPos(baseNode, targetNode) {
const worldPos = targetNode.parent.convertToWorldSpaceAR(cc.v2(targetNode.x, targetNode.y)); const worldPos = targetNode.parent.convertToWorldSpaceAR(cc.v2(targetNode.x, targetNode.y));
const localPos = baseNode.parent.convertToNodeSpaceAR(cc.v2(worldPos.x, worldPos.y)); const localPos = baseNode.parent.convertToNodeSpaceAR(cc.v2(worldPos.x, worldPos.y));
return localPos; return localPos;
} }
export function worldPosToLocalPos(worldPos, baseNode) { export function worldPosToLocalPos(worldPos, baseNode) {
const localPos = baseNode.parent.convertToNodeSpaceAR(cc.v2(worldPos.x, worldPos.y)); const localPos = baseNode.parent.convertToNodeSpaceAR(cc.v2(worldPos.x, worldPos.y));
return localPos; return localPos;
} }
export function getScaleRateBy2Node(baseNode, targetNode, maxFlag = true) { export function getScaleRateBy2Node(baseNode, targetNode, maxFlag = true) {
const worldRect1 = targetNode.getBoundingBoxToWorld(); const worldRect1 = targetNode.getBoundingBoxToWorld();
const worldRect2 = baseNode.getBoundingBoxToWorld(); const worldRect2 = baseNode.getBoundingBoxToWorld();
const sx = worldRect1.width / worldRect2.width; const sx = worldRect1.width / worldRect2.width;
const sy = worldRect1.height / worldRect2.height; const sy = worldRect1.height / worldRect2.height;
if (maxFlag) { if (maxFlag) {
return Math.max(sx, sy); return Math.max(sx, sy);
} else { } else {
return Math.min(sx, sy); return Math.min(sx, sy);
} }
} }
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);
if (cb) { if (cb) {
cc.audioEngine.setFinishCallback(audioId, () => { cc.audioEngine.setFinishCallback(audioId, () => {
cb(); cb();
}); });
} }
}); });
} }
} }
export function asyncDelay(time) {
return new Promise((resolve, reject) => {
cc.tween(cc.find('Canvas'))
.delay(time)
.call(() => {
resolve();
})
.start();
});
}
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()
}) })
} }
\ 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