Commit 9427ee84 authored by liujiangnan's avatar liujiangnan

feat: 主体功能

parent 73ff5aa0
{
"ver": "2.0.1",
"uuid": "d3f3a66c-51cd-4fcf-bc2b-8d424c4918d1",
"downloadMode": 0,
"duration": 2.319563,
"subMetas": {}
}
\ No newline at end of file
{ {
"ver": "2.0.1", "ver": "2.0.1",
"uuid": "4becf611-d0bc-4bd8-9bc9-b4d66646ada9", "uuid": "4641cae0-0d7a-4008-bc0e-ddf209310d28",
"downloadMode": 0, "downloadMode": 0,
"duration": 0.301724, "duration": 5.172245,
"subMetas": {} "subMetas": {}
} }
\ No newline at end of file
{ {
"ver": "2.0.1", "ver": "2.0.1",
"uuid": "4641cae0-0d7a-4008-bc0e-ddf209310d28", "uuid": "4becf611-d0bc-4bd8-9bc9-b4d66646ada9",
"downloadMode": 0, "downloadMode": 0,
"duration": 5.172245, "duration": 0.301724,
"subMetas": {} "subMetas": {}
} }
\ No newline at end of file
This diff is collapsed.
import { buttonOnClick, buttonOnceClick, getSpriteFrimeByUrl, asyncLoadDragonBoneAnime, asyncDelay } from "../script/util"; import { buttonOnClick, buttonOnceClick, getSpriteFrimeByUrl,
asyncGetSpriteFrimeByUrl, playAudioByUrl, asyncLoadDragonBoneAnime,
asyncDelay, setNetImg } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent"; import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -7,6 +9,21 @@ const { ccclass, property } = cc._decorator; ...@@ -7,6 +9,21 @@ const { ccclass, property } = cc._decorator;
export default class SceneComponent extends MyCocosSceneComponent { export default class SceneComponent extends MyCocosSceneComponent {
@property(cc.Node)
startNode: cc.Node = null;
@property(cc.Node)
page_view: cc.Node = null;
@property(cc.Node)
tip_label: cc.Node = null;
@property(cc.Node)
tip_left: cc.Node = null;
@property(cc.Node)
tip_right: cc.Node = null;
addPreloadImage() { addPreloadImage() {
// TODO 根据自己的配置预加载图片资源 // TODO 根据自己的配置预加载图片资源
} }
...@@ -56,7 +73,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -56,7 +73,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
async onLoadEnd() { async onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考 // TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData(); this.initData();
this.initView(); await this.initView();
await this.asyncDrawAnswer(); await this.asyncDrawAnswer();
this.initListener(); this.initListener();
} }
...@@ -68,8 +85,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -68,8 +85,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
picture_url = null; picture_url = null;
initView() { async initView() {
this.initBg(); this.initBg();
await this.initTips();
window["cameraHandler"].takePictureCallback = (err, url) => { window["cameraHandler"].takePictureCallback = (err, url) => {
if (err) { if (err) {
console.log(err); console.log(err);
...@@ -84,6 +102,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -84,6 +102,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
getSpriteFrimeByUrl(url, (frame) => { getSpriteFrimeByUrl(url, (frame) => {
pic.getComponent(cc.Sprite).spriteFrame = frame; pic.getComponent(cc.Sprite).spriteFrame = frame;
pic.active = true; pic.active = true;
this.playLocalAudio("picload");
this.hideLoading(); this.hideLoading();
}); });
} }
...@@ -95,9 +114,56 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -95,9 +114,56 @@ export default class SceneComponent extends MyCocosSceneComponent {
bgNode.scale = this._mapScaleMax; bgNode.scale = this._mapScaleMax;
} }
async initTips() {
if (this.data.tipSwitch == 0) {
cc.find("btn_start", this.node).active = false;
return;
}
this.startNode.active = true;
const data: any = await setNetImg(cc.find("s_group/startbg", this.startNode), this.data.tipBg, { w: 0, h: 0 }, false);
this.page_view.width = data.w - 240;
this.page_view.height = data.h - 200;
this.page_view.x = -(data.w / 2);
this.data.tipPage.forEach((dt, idx) => {
let desc = cc.instantiate(this.tip_label);
desc.getComponent(cc.Label).string = dt.title;
desc.width = this.page_view.width;
desc.height = this.page_view.height - 40;
this.page_view.getComponent(cc.PageView).addPage(desc);
desc.active = true;
desc["data"] = dt;
})
this.updataTipArrow();
const btnStart = cc.find("btn_start", this.node);
await asyncLoadDragonBoneAnime(btnStart, {
skeJsonData: this.data.imgAni.ske,
texJsonData: this.data.imgAni.tex,
texPngData: this.data.imgAni.png
});
const animaNode = btnStart['animaNode'];
const db = animaNode.getComponent(dragonBones.ArmatureDisplay);
let anis = db.getAnimationNames("armatureName");
db.playAnimation(anis[0], 0);
}
updataTipArrow() {
let index = this.page_view.getComponent(cc.PageView).getCurrentPageIndex();
let pages = this.page_view.getComponent(cc.PageView).getPages();
this.tip_left.active = pages.length > 0 && index > 0;
this.tip_right.active = pages.length > 0 && index < pages.length - 1;
let page = pages[index];
if (page)
playAudioByUrl(page["data"].audio);
}
initListener() { initListener() {
const btn = cc.find(`Canvas/border/upload`); const btn = cc.find(`Canvas/border/upload`);
buttonOnClick(btn, () => { buttonOnClick(btn, () => {
this.playLocalAudio("upload");
this.showLoading(); this.showLoading();
window["cameraHandler"].openCamera(); window["cameraHandler"].openCamera();
}); });
...@@ -119,6 +185,31 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -119,6 +185,31 @@ export default class SceneComponent extends MyCocosSceneComponent {
console.log("==切换下一页=="); console.log("==切换下一页==");
} }
}); });
const btnStart = cc.find("btn_start", this.node);
btnStart.on('click', () => {
if (btnStart['cantClick']) {
return;
}
btnStart['cantClick'] = true;
this.startNode.active = true;
let start_ske = btnStart['animaNode'];
cc.tween(start_ske).to(0.2, { scale: 1 }).start();
this.updataTipArrow();
});
buttonOnClick(cc.find("s_group/startbg/btn_close", this.startNode), () => {
cc.audioEngine.stopAll();
const btnStart = cc.find("btn_start", this.node);
let start_ske = btnStart['animaNode'];
cc.tween(start_ske).to(0.2, { scale: 0.3 }).call(() => {
cc.find("btn_start", this.node)['cantClick'] = false;
}).start();
this.page_view.getComponent(cc.PageView).setCurrentPageIndex(0);
this.startNode.active = false;
});
} }
async showFinal() { async showFinal() {
...@@ -133,12 +224,13 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -133,12 +224,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
texJsonData: this.data.endImgAni.tex, texJsonData: this.data.endImgAni.tex,
texPngData: this.data.endImgAni.png texPngData: this.data.endImgAni.png
}); });
const animaNode = f_group['animaNode']; const animaNode = f_group['animaNode'];
const db = animaNode.getComponent(dragonBones.ArmatureDisplay); const db = animaNode.getComponent(dragonBones.ArmatureDisplay);
let anis = db.getAnimationNames("armatureName"); let anis = db.getAnimationNames("armatureName");
db.playAnimation(anis[0], 0); db.playAnimation(anis[0], 0);
this.playLocalAudio("success");
final.active = true; final.active = true;
let desc = cc.find("desc", f_group); let desc = cc.find("desc", f_group);
let final_title = cc.find("final_title", f_group); let final_title = cc.find("final_title", f_group);
...@@ -161,13 +253,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -161,13 +253,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
playLocalAudio(audioName) { playLocalAudio(audioName) {
cc.audioEngine.stopAll();
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource); const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => { cc.audioEngine.playEffect(audio.clip, false);
const id = cc.audioEngine.playEffect(audio.clip, false);
cc.audioEngine.setFinishCallback(id, () => {
resolve(id);
});
})
} }
onLeave(cb) { onLeave(cb) {
......
...@@ -19,7 +19,7 @@ export const defaultData = { ...@@ -19,7 +19,7 @@ export const defaultData = {
"tipPage": [ "tipPage": [
{ {
"title": "这么小的院子里,居然同时有一间书房和一间书院,这家人可真喜欢读书啊。", "title": "这么小的院子里,居然同时有一间书房和一间书院,这家人可真喜欢读书啊。",
"audio": "" "audio": "https://staging-teach.cdn.ireadabc.com/c03129693e6cabf061661fba349fa031.mp3"
} }
], ],
"title": "", "title": "",
......
...@@ -143,6 +143,54 @@ export function getSpriteFrimeByUrl(url, cb) { ...@@ -143,6 +143,54 @@ export function getSpriteFrimeByUrl(url, cb) {
}) })
} }
export function asyncGetSpriteFrimeByUrl(url) {
return new Promise((resolve, reject) => {
cc.loader.load({ url }, (err, img) => {
if (err) {
reject(err);
return;
}
const spriteFrame = new cc.SpriteFrame(img)
resolve(spriteFrame);
})
});
}
export function setNetImg(item, res, { w, h }, custom = true) {
return new Promise((resolve, reject) => {
if (!item) return console.warn("图片更换失败,传入了错误的item");
let node = item.node ? item.node : item;
if (!res) {
if (node) node.active = false;
return console.warn("图片更换失败,传入了错误的res");
}
if (!node) return console.warn("图片更换失败,传入了错误的item");
if (node.net_url == res) return;
node.active = false;//
cc.loader.load({ url: res }, (err, texture) => {
if (err && !texture) return resolve(console.warn('loading loadRes warn-> ' + texture));
if (!cc.isValid(node)) return console.info("节点已销毁");
let nw = node.width = texture.width;
let nh = node.height = texture.height;
let component = node.getComponent(cc.Sprite);
let spriteFrame = new cc.SpriteFrame(texture);
component.spriteFrame = spriteFrame;
node.net_url = res;
if (!cc.isValid(node)) return console.info("节点已销毁");
if (!node) return console.warn("节点已销毁");
if (w && h && custom) {
let scaleX = w / nw;
let scaleY = h / nh;
let scale = scaleX <= scaleY ? scaleX : scaleY;
node.width = nw * scale;
node.height = nh * scale;
}
node.active = true;
resolve({ w: nw, h: nh });
});
})
}
export function getSprNode(resName) { export function getSprNode(resName) {
const sf = cc.find('Canvas/res/img/' + resName).getComponent(cc.Sprite).spriteFrame; const sf = cc.find('Canvas/res/img/' + resName).getComponent(cc.Sprite).spriteFrame;
const node = new cc.Node(); const node = new cc.Node();
......
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