Commit 19534f5f authored by Tt's avatar Tt

增加小迪

parent 0a8390ce
......@@ -13,8 +13,10 @@ class Emitter {
this._callbacks = {};
return this;
}
clear() {
this._callbacks = {};
}
on(event, fn) {
this.off(event);
if (!this._callbacks[event]) this._callbacks[event] = [];
this._callbacks[event].push(fn);
};
......@@ -26,7 +28,7 @@ class Emitter {
on.fn = fn;
this.on(event, on);
};
off(event, fn?: any) {
off(event, fn) {
// all
if (0 == arguments.length) {
this._callbacks = {};
......@@ -73,6 +75,39 @@ class Emitter {
return !!this.listeners(event).length;
};
}
class TimeCtrl {
private current: number;
constructor() {
this.current = 0;
}
fillTime(time) {
this.current += (time * 1000)
return this;
}
setTime(time) {
this.current += (time * 1000)
return this;
}
wait() {
return new Promise((resolve, reject) => {
let lastTime = new Date().getTime();
let id = setInterval(() => {
let nowTime = new Date().getTime();
this.current -= (nowTime - lastTime);
lastTime = nowTime;
if (this.current <= 0) {
clearInterval(id);
resolve(true);
}
}, 1)
});
}
reset() {
this.current = 0;
return this;
}
}
let pg = {
logger: {
d: function (str) {
......@@ -227,9 +262,15 @@ let pg = {
if (!cc.isValid(node)) return pg.logger.i("节点已销毁");
if (!node) return pg.logger.w("节点已销毁");
if (w && h) {
// 宽高都需要匹配
let scaleX = w / nw;
let scaleY = h / nh;
let scale = scaleX <= scaleY ? scaleX : scaleY;
node.width = nw * scaleX;
node.height = nh * scaleY;
} else if (w && !h) {
// 只匹配宽
let scale = w / nw;
node.width = nw * scale;
node.height = nh * scale;
}
......@@ -238,6 +279,18 @@ let pg = {
})
})
},
setNodeImg(item, target) {
return new Promise((resolve, reject) => {
if (!item) return pg.logger.w("图片更换失败,传入了错误的item");
let spriteFrame = target.getComponent(cc.Sprite).spriteFrame;
let node = item.node ? item.node : item;
if (!cc.isValid(node)) return pg.logger.i("节点已销毁");
let component = node.getComponent(cc.Sprite);
let { width, height } = spriteFrame.getRect();
component.spriteFrame = spriteFrame;
resolve({ width, height });
})
},
switchMaterial(item, id0 = 0, id1 = 1) {
let material0 = item.getMaterial(id0);
let material1 = item.getMaterial(id1);
......@@ -471,14 +524,29 @@ let pg = {
}
},
audio: {
playAudioByUrl(audio_url) {
playAudioByUrl(audio_url, cb = null, loadCb = null) {
return new Promise((resolve, reject) => {
if (!audio_url) return resolve(null);
cc.assetManager.loadRemote(audio_url, (err, audioClip: any) => {
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
cc.audioEngine.setFinishCallback(audioId, () => {
resolve(audioId);
cb && cb();
});
loadCb && loadCb(audioId);
resolve(audioId);
});
});
},
playBgAudioByUrl(audio_url, cb = null, loadCb = null) {
return new Promise((resolve, reject) => {
if (!audio_url) return resolve(null);
cc.assetManager.loadRemote(audio_url, (err, audioClip: any) => {
const audioId = cc.audioEngine.playMusic(audioClip, true);
cc.audioEngine.setFinishCallback(audioId, () => {
cb && cb();
});
loadCb && loadCb(audioId);
resolve(audioId);
});
});
},
......@@ -486,18 +554,46 @@ let pg = {
if (!audioId) return;
cc.audioEngine.stopEffect(audioId);
},
playAudio(audioClip, cb = null) {
if (audioClip) {
const audioId = cc.audioEngine.playEffect(audioClip, false);
if (cb) {
cc.audioEngine.setFinishCallback(audioId, () => {
cb();
cb && cb();
});
}
return audioId;
}
},
playLocalAudio(audio: cc.Node) {
return new Promise((resolve, reject) => {
const id = cc.audioEngine.playEffect(audio.getComponent(cc.AudioSource).clip, false);
cc.audioEngine.setFinishCallback(id, () => {
resolve(id);
});
})
},
getAudioClip(audio_url) {
return new Promise((resolve, reject) => {
if (!audio_url) return resolve(null);
cc.assetManager.loadRemote(audio_url, (err, audioClip: any) => {
resolve(audioClip);
});
});
}
},
time: {
delay(time) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('');
}, time * 1000);
});
},
delayCtrl(): TimeCtrl {
return new TimeCtrl();
}
},
hw: {
......@@ -512,4 +608,4 @@ let pg = {
},
event: Emitter.getInstance()
};
export default pg;
\ No newline at end of file
export default pg;
import pg from "./pg";
const { ccclass, property } = cc._decorator;
@ccclass
export default class dg_xiaodi extends cc.Component {
@property(cc.Node)
aniRole: cc.Node = null;
@property moveX: number = 500;
private defaultX: number;
onLoad() {
this.defaultX = this.aniRole.x;
}
private audioIdEnter: any;
playEnter(audioUrl) {
return new Promise((resolve, reject) => {
this.node.active = true;
let startX = this.defaultX + this.moveX;
this.aniRole.x = startX;
cc.tween(this.aniRole)
.call(() => {
pg.view.playDBAnimation(this.aniRole, 'run');
if (this.moveX < 0) {
this.aniRole.scaleX = -this.aniRole.scaleX;
}
})
.to(0.5, { x: 0 })
.call(() => {
if (this.moveX < 0) {
this.aniRole.scaleX = -this.aniRole.scaleX;
}
pg.view.playDBAnimation(this.aniRole, 'talk');
pg.audio.playAudioByUrl(audioUrl, () => {
this.audioIdEnter = null;
cc.tween(this.aniRole)
.call(() => {
pg.view.playDBAnimation(this.aniRole, 'run');
if (this.moveX < 0) {
this.aniRole.scaleX = -this.aniRole.scaleX;
}
})
.to(0.5, { x: -1500 })
.call(() => {
this.scheduleOnce(() => {
resolve('');
}, 0.5)
})
.start();
}, audioId => {
this.audioIdEnter = audioId;
})
})
.start();
});
}
playEnterEnd() {
this.node.active = false;
if (this.audioIdEnter) {
cc.audioEngine.stopEffect(this.audioIdEnter)
}
}
private audioIdOver: any;
playOver(audioUrl) {
this.node.active = true;
let startX = this.defaultX + this.moveX;
this.aniRole.x = startX;
cc.tween(this.aniRole)
.call(() => {
pg.view.playDBAnimation(this.aniRole, 'run');
if (this.moveX < 0) {
this.aniRole.scaleX = -this.aniRole.scaleX;
}
})
.to(0.3, { x: this.defaultX })
.call(() => {
if (this.moveX < 0) {
this.aniRole.scaleX = -this.aniRole.scaleX;
}
pg.view.playDBAnimation(this.aniRole, 'talk');
pg.audio.playAudioByUrl(audioUrl, () => {
this.audioIdOver = null;
pg.view.playDBAnimation(this.aniRole, 'normal');
}, audioId => {
this.audioIdOver = audioId;
})
})
.start();
}
playOverEnd() {
this.node.active = false;
if (this.audioIdOver) {
cc.audioEngine.stopEffect(this.audioIdOver)
}
}
start() {
}
update(dt) {
}
}
{
"ver": "1.0.8",
"uuid": "e017e44d-1470-4c4d-b7b1-154e34a35d8c",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "d796c170-40d5-4ac4-835a-58acf8f40fe2",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "cdb949fe-8e2d-4cbd-bd43-f36cb9113c04",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 265,
"height": 175,
"platformSettings": {},
"subMetas": {
"btn_go_dg07_fanka": {
"ver": "1.0.4",
"uuid": "a53cbf71-f5e8-413f-8ca5-5d78b08c2680",
"rawTextureUuid": "cdb949fe-8e2d-4cbd-bd43-f36cb9113c04",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": -4,
"offsetY": 1.5,
"trimX": 0,
"trimY": 3,
"width": 257,
"height": 166,
"rawWidth": 265,
"rawHeight": 175,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.0.1",
"uuid": "1f3903cb-1d5e-4e59-8440-b4cc1eb2e9d7",
"subMetas": {}
}
\ No newline at end of file
{"width":2048,"height":2048,"name":"小迪","imagePath":"xiaodi_tex_dg07_fanka.png","SubTexture":[{"width":79,"y":210,"height":67,"name":"run/图层_73","x":1394},{"width":133,"y":810,"height":178,"name":"run/图层 61_0","x":1349},{"width":30,"y":1452,"height":71,"name":"run/图层_65","x":479},{"width":122,"y":1049,"height":99,"name":"run/图层44","x":1892},{"width":332,"y":1,"height":207,"name":"run/图层_64","x":1148},{"width":82,"y":670,"height":123,"name":"run/图层38(2)","x":1952},{"width":244,"y":210,"height":266,"name":"run/图层_68","x":1148},{"width":249,"y":1,"height":285,"name":"run/身体","x":897},{"width":71,"y":1526,"height":77,"name":"run/图层_66","x":156},{"width":87,"y":1607,"height":87,"name":"run/图层_72","x":156},{"width":241,"y":1295,"height":127,"name":"run/图层_61","x":1},{"width":454,"y":1,"height":413,"name":"run/头","x":1},{"width":48,"y":612,"height":47,"name":"run/嘴巴","x":1785},{"width":64,"y":664,"height":76,"name":"run/眼睛","x":1033},{"width":243,"y":428,"height":199,"name":"run/闭眼","x":441},{"width":64,"y":748,"height":76,"name":"run/半睁","x":1713},{"width":59,"y":1547,"height":15,"name":"run/图层_74","x":312},{"width":242,"y":1001,"height":130,"name":"run/眼镜","x":599},{"width":118,"y":928,"height":119,"name":"run/耳套","x":1892},{"width":126,"y":1355,"height":95,"name":"expect/左脚_0","x":390},{"width":126,"y":1165,"height":94,"name":"good/右脚","x":1420},{"width":196,"y":280,"height":263,"name":"expect/图层 45_0","x":1394},{"width":137,"y":734,"height":265,"name":"good/右腿","x":636},{"width":126,"y":1262,"height":95,"name":"expect/左脚","x":762},{"width":127,"y":1086,"height":94,"name":"good/左脚","x":1670},{"width":196,"y":478,"height":263,"name":"expect/图层_45","x":1127},{"width":143,"y":838,"height":265,"name":"good/左腿","x":255},{"width":153,"y":1424,"height":193,"name":"talk/图层_47","x":1},{"width":153,"y":743,"height":185,"name":"talk/右手前","x":1064},{"width":133,"y":930,"height":142,"name":"good/图层_46","x":1084},{"width":224,"y":798,"height":199,"name":"wave/图层43","x":838},{"width":167,"y":314,"height":176,"name":"expect/图层 37_2","x":1848},{"width":165,"y":670,"height":165,"name":"good/图层 35_0","x":1785},{"width":237,"y":314,"height":153,"name":"cheer/图层_37","x":1592},{"width":128,"y":1,"height":202,"name":"good/图层35_0","x":1909},{"width":199,"y":1137,"height":121,"name":"invite/图层_30","x":1219},{"width":219,"y":612,"height":134,"name":"cheer/图层 46_0","x":1564},{"width":197,"y":1033,"height":163,"name":"good/右手2_0","x":400},{"width":150,"y":1218,"height":104,"name":"good/图层34_0","x":1017},{"width":96,"y":1262,"height":110,"name":"expect/图层 39_1","x":890},{"width":71,"y":1374,"height":90,"name":"good/图层40","x":834},{"width":152,"y":915,"height":138,"name":"invite/图层 31_0","x":1484},{"width":80,"y":560,"height":102,"name":"good/图层_36","x":1033},{"width":88,"y":1421,"height":92,"name":"talk/图层42","x":608},{"width":100,"y":1165,"height":92,"name":"wave/图层42","x":1548},{"width":90,"y":1086,"height":87,"name":"cheer/图层42_0","x":1799},{"width":88,"y":1355,"height":92,"name":"cheer/图层42_1","x":518},{"width":193,"y":629,"height":236,"name":"good/图层 44_0","x":441},{"width":167,"y":492,"height":176,"name":"expect/图层 37_1","x":1848},{"width":132,"y":1074,"height":142,"name":"good/图层 46_0","x":1084},{"width":199,"y":1014,"height":121,"name":"invite/图层 30_0","x":1219},{"width":165,"y":748,"height":165,"name":"good/图层_35","x":1546},{"width":206,"y":1198,"height":155,"name":"talk/图层_46","x":400},{"width":128,"y":810,"height":202,"name":"good/图层35","x":1219},{"width":252,"y":838,"height":161,"name":"wave/图层43_0","x":1},{"width":219,"y":674,"height":134,"name":"cheer/图层_46","x":1325},{"width":231,"y":1001,"height":164,"name":"cheer/图层 37_0","x":1},{"width":197,"y":867,"height":164,"name":"good/右手2","x":400},{"width":76,"y":1505,"height":100,"name":"good/图层47_0","x":234},{"width":228,"y":288,"height":270,"name":"good/身体","x":897},{"width":149,"y":1105,"height":174,"name":"wave/图层_45","x":248},{"width":96,"y":1359,"height":110,"name":"expect/图层 39_2","x":736},{"width":193,"y":560,"height":236,"name":"good/图层_44","x":838},{"width":90,"y":1607,"height":84,"name":"cheer/图层42","x":245},{"width":79,"y":1449,"height":102,"name":"good/图层 36_0","x":518},{"width":152,"y":1133,"height":138,"name":"invite/图层_31","x":608},{"width":87,"y":1471,"height":91,"name":"cheer/图层42_2","x":390},{"width":84,"y":1182,"height":84,"name":"talk/图层40","x":1650},{"width":86,"y":1619,"height":84,"name":"wave/图层_44","x":1},{"width":71,"y":1324,"height":90,"name":"good/图层40_0","x":1062},{"width":29,"y":838,"height":20,"name":"wave/图层_25","x":400},{"width":438,"y":416,"height":420,"name":"good/头","x":1},{"width":221,"y":1564,"height":32,"name":"expect/眉毛","x":312},{"width":220,"y":1357,"height":23,"name":"invite/眉毛","x":1357},{"width":220,"y":1341,"height":25,"name":"good/眉毛","x":1135},{"width":220,"y":1330,"height":25,"name":"talk/眉毛","x":1415},{"width":43,"y":280,"height":32,"name":"wave/张嘴","x":1660},{"width":44,"y":1150,"height":17,"name":"good/闭嘴","x":1891},{"width":70,"y":1505,"height":40,"name":"cheer/张嘴","x":312},{"width":57,"y":902,"height":22,"name":"cheer/闭嘴","x":1954},{"width":70,"y":1133,"height":40,"name":"expect/张嘴","x":762},{"width":66,"y":280,"height":26,"name":"expect/闭嘴","x":1592},{"width":44,"y":990,"height":17,"name":"invite/闭嘴","x":1349},{"width":44,"y":1218,"height":26,"name":"invite/张嘴","x":1169},{"width":44,"y":1452,"height":17,"name":"talk/闭嘴","x":390},{"width":44,"y":990,"height":26,"name":"talk/张嘴","x":1420},{"width":44,"y":1018,"height":26,"name":"good/张嘴","x":1420},{"width":43,"y":1046,"height":26,"name":"wave/闭嘴","x":1420},{"width":44,"y":690,"height":26,"name":"good/张嘴_0","x":636},{"width":239,"y":837,"height":89,"name":"wave/闭眼","x":1713},{"width":252,"y":1007,"height":77,"name":"good/半睁","x":1638},{"width":245,"y":1167,"height":126,"name":"wave/睁眼_0","x":1},{"width":247,"y":1175,"height":30,"name":"good/闭眼","x":1799},{"width":237,"y":545,"height":127,"name":"wave/睁眼","x":1325},{"width":244,"y":1302,"height":37,"name":"cheer/闭眼","x":1169},{"width":253,"y":1183,"height":77,"name":"expect/睁眼","x":762},{"width":248,"y":1086,"height":77,"name":"good/睁眼","x":1420},{"width":244,"y":1261,"height":37,"name":"invite/闭眼","x":1403},{"width":252,"y":928,"height":77,"name":"good/睁眼_0","x":1638},{"width":39,"y":629,"height":59,"name":"expect/图层 36_0","x":636},{"width":39,"y":478,"height":59,"name":"expect/图层_36","x":1325},{"width":126,"y":1324,"height":95,"name":"point/左脚","x":608},{"width":150,"y":428,"height":304,"name":"point/左腿","x":686},{"width":125,"y":205,"height":103,"name":"point/右脚","x":1909},{"width":186,"y":1,"height":311,"name":"point/右腿","x":1721},{"width":87,"y":795,"height":105,"name":"point/图层42","x":1954},{"width":254,"y":469,"height":141,"name":"point/已插入图像_1","x":1592},{"width":76,"y":1424,"height":100,"name":"point/图层47","x":156},{"width":237,"y":1,"height":277,"name":"point/身体","x":1482},{"width":76,"y":1268,"height":92,"name":"point/图层34","x":1650},{"width":438,"y":1,"height":425,"name":"point/头","x":457},{"width":239,"y":1091,"height":90,"name":"point/睁眼","x":843},{"width":239,"y":999,"height":90,"name":"point/半睁","x":843},{"width":232,"y":1260,"height":40,"name":"point/闭眼","x":1169},{"width":223,"y":1300,"height":28,"name":"point/眉毛","x":1415},{"width":63,"y":1183,"height":30,"name":"point/嘴巴1","x":1017},{"width":24,"y":742,"height":41,"name":"point/嘴巴2","x":1033},{"width":144,"y":1295,"height":208,"name":"point/已插入图像","x":244},{"width":72,"y":1324,"height":90,"name":"point/已插入图像_0","x":988}]}
\ No newline at end of file
{
"ver": "1.0.1",
"uuid": "6588a98c-c9fc-47e6-9992-d9f5e712b6de",
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "2.3.5",
"uuid": "dcdb99b1-145a-43a1-949c-e3b36b7426fa",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 2048,
"height": 2048,
"platformSettings": {},
"subMetas": {
"xiaodi_tex_dg07_fanka": {
"ver": "1.0.4",
"uuid": "fe7f7a8f-6f5f-46f7-8219-8565b6bbf1b7",
"rawTextureUuid": "dcdb99b1-145a-43a1-949c-e3b36b7426fa",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": -0.5,
"offsetY": 172,
"trimX": 1,
"trimY": 1,
"width": 2045,
"height": 1702,
"rawWidth": 2048,
"rawHeight": 2048,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"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