Commit 9d26ddce authored by Tt's avatar Tt

data引用错误调整

parent 7ea64f87
import Data from "../script/defaultData";
interface Item { interface Item {
id: number; id: number;
text: string; text: string;
...@@ -14,6 +13,7 @@ export default class Game { ...@@ -14,6 +13,7 @@ export default class Game {
} }
private lists: Array<any> private lists: Array<any>
private nowStem: any; private nowStem: any;
private data: any;
public pause: boolean; public pause: boolean;
public isRobot: boolean; public isRobot: boolean;
public playerScore: number; public playerScore: number;
...@@ -22,8 +22,10 @@ export default class Game { ...@@ -22,8 +22,10 @@ export default class Game {
constructor() { constructor() {
// //
this.start = false; this.start = false;
this.data = null;
} }
public init() { public init(data) {
this.data = data;
this.start = false; this.start = false;
this.lists = null; this.lists = null;
this.nowStem = null; this.nowStem = null;
...@@ -36,7 +38,7 @@ export default class Game { ...@@ -36,7 +38,7 @@ export default class Game {
public start: boolean; public start: boolean;
reset() { reset() {
this.start = true; this.start = true;
this.lists = JSON.parse(JSON.stringify(Data.list)); this.lists = JSON.parse(JSON.stringify(this.data.list));
this.pause = false; this.pause = false;
this.isRobot = false; this.isRobot = false;
this.playerScore = 0; this.playerScore = 0;
......
...@@ -48,7 +48,7 @@ export default class NewClass extends MyCocosSceneComponent { ...@@ -48,7 +48,7 @@ export default class NewClass extends MyCocosSceneComponent {
this.log("test initData") this.log("test initData")
// 所有全局变量 默认都是null // 所有全局变量 默认都是null
this._cantouch = true; this._cantouch = true;
Game.getIns().init(); Game.getIns().init(this.data);
//开始显示企鹅 //开始显示企鹅
} }
initView() { initView() {
......
...@@ -105,17 +105,17 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -105,17 +105,17 @@ export class MyCocosSceneComponent extends cc.Component {
}); });
} }
log (str) { log(str) {
const node = cc.find('middleLayer'); const node = cc.find('middleLayer');
if(node){ if (node) {
node.getComponent('middleLayer').log(str); node.getComponent('middleLayer').log(str);
}else{ } else {
cc.log(str); cc.log(str);
} }
} }
onLoadEnd() { onLoadEnd() {
} }
...@@ -132,7 +132,7 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -132,7 +132,7 @@ export class MyCocosSceneComponent extends cc.Component {
// ------------------------------------------------ // ------------------------------------------------
getSprNode(resName) { 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;
...@@ -164,7 +164,7 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -164,7 +164,7 @@ export class MyCocosSceneComponent extends cc.Component {
playAudioByUrl(audio_url, cb = null) { 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: any) => {
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, () => {
...@@ -172,7 +172,7 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -172,7 +172,7 @@ export class MyCocosSceneComponent extends cc.Component {
}); });
} }
}); });
}else{ } else {
cb && cb(); cb && cb();
} }
} }
......
export default { export const defaultData = {
"list": "list":
[ [
{ {
......
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