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

test

parent 29470d78
......@@ -5,7 +5,7 @@
// Learn life-cycle callbacks:
// - 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({
extends: cc.Component,
......@@ -965,11 +965,22 @@ cc.Class({
return;
}
cc.loader.load(image, (error, texture) => {
cc.loader.load({ url: atlas, type: 'txt' }, (error, atlasJson) => {
cc.loader.load({ url: ske, type: 'txt' }, (error, dragonBonesJson) => {
cc.loader.load(image, async (error, texture) => {
this.log('error: ' + error);
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');
await asyncDelay(3);
const atlas = new dragonBones.DragonBonesAtlasAsset();
atlas.atlasJson = atlasJson;
atlas.texture = texture;
......@@ -984,13 +995,16 @@ cc.Class({
let armatures = json["armature"];
// console.log('armatures: ', armatures);
let armatureNames = [];
await asyncDelay(3);
this.log('汪汪汪2');
for (let i = 0; i < armatures.length; i++) {
armatureNames.push(armatures[i].name);
}
await asyncDelay(3);
this.log('汪汪汪3');
// console.log('armatureNames: ', armatureNames);
if (armatureNames.length > 0) {
await asyncDelay(3);
this.log('汪汪汪4');
let defaultArmatureName = armatureNames[0];
dragonDisplay.armatureName = defaultArmatureName;
......@@ -1007,12 +1021,14 @@ cc.Class({
dragonDisplay.playAnimation('normal', -1);
dragonDisplay.animaNames = animationNames;
animaNode.y -= 30;
await asyncDelay(3);
this.log('汪汪汪5');
if (animaNode.height) {
animaNode.scale = 376 / animaNode.height;
}
}
await asyncDelay(3);
this.log('汪汪汪');
});
});
......
......@@ -71,64 +71,74 @@ export function setSprNodeMaxLen(sprNode, maxW, maxH) {
}
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;
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;
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);
}
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 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) => {
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 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.on(cc.Node.EventType.TOUCH_START, () => {
cc.tween(btn)
.to(time / 2, {scale: btn.scale * rate})
.to(time / 2, { scale: btn.scale * rate })
.start()
})
btn.on(cc.Node.EventType.TOUCH_CANCEL, () => {
cc.tween(btn)
.to(time / 2, {scale: btn.tmpScale})
.to(time / 2, { scale: btn.tmpScale })
.start()
})
btn.on(cc.Node.EventType.TOUCH_END, () => {
cc.tween(btn)
.to(time / 2, {scale: btn.tmpScale})
.to(time / 2, { scale: btn.tmpScale })
.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