Commit 79069541 authored by 杨一航's avatar 杨一航

feat;

parent 41336c91
This diff is collapsed.
import { asyncDelay, onHomeworkFinish } from "../script/util_DG25"; import { getSpriteFrimeByUrl, goNextPage, onHomeworkFinish } from "../script/util_DG25";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent_DG25"; import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent_DG25";
import Boy from "../script/items/boy_DG25";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class SceneComponent extends MyCocosSceneComponent { export default class SceneComponent extends MyCocosSceneComponent {
@property(cc.Node)
boyNode: cc.Node = null;
@property(cc.Node)
bgIcon: cc.Node = null;
@property(cc.Node)
rect: cc.Node = null;
@property(cc.Node)
box: cc.Node = null;
@property(cc.Node)
btn_next: cc.Node = null;
_bgIconUrl: any;
_item_1_data: any;
_item_2_data: any;
_itemOffsetx: any;
_itemOffsety: any;
private _itemList: any;
addPreloadImage() { addPreloadImage() {
// TODO 根据自己的配置预加载图片资源 // TODO 根据自己的配置预加载图片资源
...@@ -14,7 +31,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -14,7 +31,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
addPreloadAudio() { addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源 // TODO 根据自己的配置预加载音频资源
// this._audioResList.push({ url: this.data.audio_url }); this._audioResList.push({ url: this.data.start_audio_url });
this._audioResList.push({ url: this.data.end_audio_url });
} }
addPreloadAnima() { addPreloadAnima() {
...@@ -22,6 +40,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -22,6 +40,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
async onLoadEnd() { async onLoadEnd() {
cc.log(JSON.stringify(this.data, null, 2))
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考 // TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData(); this.initData();
this.initView(); this.initView();
...@@ -36,17 +56,112 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -36,17 +56,112 @@ export default class SceneComponent extends MyCocosSceneComponent {
initView() { initView() {
this.initBg(); this.initBg();
this.initPageData();
this.initPageView();
this.boyNode.getComponent(Boy).playtalk(-1);
this.playAudioByUrl(this.data.start_audio_url, () => {
this.boyNode.getComponent(Boy).playNormal();
})
} }
initBg() { initBg() {
const bgNode = cc.find('Canvas/bg'); const bgNode = cc.find('Canvas/bg');
bgNode.scale = this._mapScaleMax; bgNode.scale = this._mapScaleMax;
this.btn_next.on("click", () => {
cc.audioEngine.stopAllEffects();
goNextPage()
})
} }
initPageData() {
this._bgIconUrl = this.data.bgItem.url;
this._itemList = this.data.hotZoneItemArr || [];
}
initPageView() {
this.btn_next.active = false;
if (this.data.end_btn_text) {
this.btn_next.active = true;
this.btn_next.getChildByName("lb").getComponent(cc.Label).string = this.data.end_btn_text;
}
this.rect.removeAllChildren();
if (this._bgIconUrl) {
getSpriteFrimeByUrl(this._bgIconUrl, (spf) => {
this.bgIcon.getComponent(cc.Sprite).spriteFrame = spf;
this.bgIcon.width = this.data.bgItem.rect.width;
this.bgIcon.height = this.data.bgItem.rect.height;
this.rect.getComponent(cc.Widget).updateAlignment();
this.bgIcon.scale = Math.min(1100 / this.bgIcon.width, 660 / this.bgIcon.height)
})
}
let doneAudioIndex = 0;
for (let i = 0; i < this._itemList.length; ++i) {
let itemInfo = this._itemList[i];
let item = cc.instantiate(this.box);
item.parent = this.rect;
item.width = itemInfo.rect.width;
item.height = itemInfo.rect.height;
item.x = itemInfo.rect.x + itemInfo.rect.width / 2;
item.y = -itemInfo.rect.y - itemInfo.rect.height / 2;
item.addComponent(cc.Button);
cc.log("item scale == " + item.scale)
item.on("click", () => {
cc.audioEngine.stopAllEffects();
this.boyNode.getComponent(Boy).playNormal();
this.rect.children.forEach((val) => {
val.stopAllActions();
val.scale = 1;
})
if (!item["doneAudio"]) {
item["doneAudio"] = true;
doneAudioIndex++;
}
cc.tween(item).to(0.5, { scale: 1.05 }).to(0.5, { scale: 1 }).start()
this.playAudioByUrl(itemInfo.audio_url, () => {
this.ckeckEnd(doneAudioIndex);
})
})
if (itemInfo.pic_url) {
item.getChildByName("icon").active = true;
getSpriteFrimeByUrl(itemInfo.pic_url, (spf) => {
item.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = spf;
item.getChildByName("icon").scale = itemInfo.imgScale;
// this.bgIcon.scale = Math.min(1100 / this.bgIcon.width, 660 / this.bgIcon.height)
})
} else {
item.getChildByName("icon").active = false;
}
if (itemInfo.text) {
item.getChildByName("lb").active = true;
item.getChildByName("lb").getComponent(cc.Label).string = itemInfo.text;
} else {
item.getChildByName("lb").active = false;
}
}
}
ckeckEnd(nowIndex) {
if (nowIndex == this._itemList.length) {
cc.log("donve");
this.boyNode.getComponent(Boy).playtalk(-1);
this.playAudioByUrl(this.data.end_audio_url, () => {
this.boyNode.getComponent(Boy).playNormal();
})
}
}
......
export const defaultData = { export const defaultData =
"pic_url": "http://staging-teach.cdn.ireadabc.com/ed94332a503c31e0908bd4c6923a2665.png", {
"pic_url_2": "http://staging-teach.cdn.ireadabc.com/5fb60317ade0195d35ad8034d5370a7f.png", "bgItem": {
"text": "This is a test label.", "url": "http://staging-teach.cdn.ireadabc.com/b98081742d4fd40f42e24284c89f48d9.png",
"audio_url": "http://staging-teach.cdn.ireadabc.com/f47f1d7b5c160fe1c59500d180346240.mp3" "rect": {
"x": 193.39,
"y": 0,
"width": 830.22,
"height": 467
}
},
"hotZoneItemArr": [
{
"id": "1700553479578",
"index": 0,
"pic_url": "http://staging-teach.cdn.ireadabc.com/ed1741e9231dd320033bf4ecbf283b0f.png",
"audio_url": "http://staging-teach.cdn.ireadabc.com/12eb0567ca90c61fc42964bd8344e8b3.mp3",
"itemType": "pic",
"fontScale": 0.95078125,
"imgScale": 0.2627906976744186,
"mapScale": 0.95078125,
"gIdx": "1",
"rect": {
"x": 75.86,
"y": 42.42,
"width": 247.81,
"height": 113
}
},
{
"id": "1700553482079",
"index": 1,
"pic_url": "http://staging-teach.cdn.ireadabc.com/727701ba34634c7d90cf794808064280.png",
"audio_url": "http://staging-teach.cdn.ireadabc.com/5e0ae1de90cff001bd0f6798341e723b.mp3",
"itemType": "pic",
"fontScale": 0.95078125,
"imgScale": 0.2534883720930233,
"mapScale": 0.95078125,
"gIdx": "1",
"rect": {
"x": 528.41,
"y": 48.46,
"width": 239.04,
"height": 109
}
}
],
"start_audio_url": "http://staging-teach.cdn.ireadabc.com/e66bac8d77385b01ce180987c9a0c601.mp3",
"end_audio_url": "http://staging-teach.cdn.ireadabc.com/9541b250b13a284ca28abf87ab0bdedb.mp3",
"end_btn_text": "去故事乐园"
} }
\ No newline at end of file
...@@ -416,3 +416,12 @@ export function getMinLv(num) { ...@@ -416,3 +416,12 @@ export function getMinLv(num) {
} }
} }
export function goNextPage() {
if (!cc.find('middleLayer')) {
console.log("==点击了下一页按钮==")
return;
}
const middleLayer = cc.find('middleLayer').getComponent('middleLayer');
middleLayer.goNextPage();
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "6aa31b3f-3dab-417a-b393-803509a6ead4",
"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": "66adddc2-6f77-4b14-b2bf-5b0e6da5ea60",
"rawTextureUuid": "6aa31b3f-3dab-417a-b393-803509a6ead4",
"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
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