53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
imagePrefab: {
|
|
default: null,
|
|
type: cc.Prefab
|
|
},
|
|
imageNode: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
imgs: []
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
onLoad () {
|
|
for (let i = 0; i < 9; i++) {
|
|
var img = cc.instantiate(this.imagePrefab);
|
|
img.getComponent('puzzleImage').imgIndex = i;
|
|
img.getComponent('puzzleImage').type = 0;
|
|
this.imageNode.addChild(img);
|
|
let x = 0;
|
|
let y = 0;
|
|
if (i < 3) {
|
|
y = 202;
|
|
} else if (i > 5) {
|
|
y = -202;
|
|
}
|
|
if (i % 3 === 0) {
|
|
x = -202;
|
|
} else if (i % 3 === 2) {
|
|
x = 202;
|
|
}
|
|
img.setPosition(cc.v2(x, y));
|
|
img.active = false;
|
|
this.imgs.push(img);
|
|
}
|
|
|
|
},
|
|
|
|
start () {
|
|
},
|
|
|
|
// update (dt) {},
|
|
updateValues(valArr) {
|
|
for(let i = 0; i < this.imgs.length; i++) {
|
|
this.imgs[i].active = !!valArr[i]
|
|
}
|
|
}
|
|
});
|