MapEnvirment.ts 928 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. const {ccclass, property} = cc._decorator;
  2. @ccclass
  3. export default class MapEnvirment extends cc.Component {
  4. // @property(cc.Sprite)
  5. // private bg: cc.Sprite = null;
  6. // @property(cc.Sprite)
  7. // private front: cc.Sprite = null;
  8. @property([cc.Node])
  9. private bgs: cc.Node[] = [];
  10. @property([cc.Node])
  11. private fronts: cc.Node[] = [];
  12. start () {
  13. this.changeMap(1);
  14. }
  15. changeMap(forceIdx:number=-1) {
  16. let me = this;
  17. let idx = Util.random(0, this.bgs.length - 1, true);
  18. if (forceIdx>=0) {
  19. idx = forceIdx;
  20. }
  21. // return;
  22. // me.bg.spriteFrame = this.bgs[idx];
  23. // me.front.spriteFrame = this.fronts[idx];
  24. // console.error("changeMap:" + idx);
  25. for (let i = 0; i < this.bgs.length; i++) {
  26. this.bgs[i].active = i == idx;
  27. // this.fronts[i].active = i == idx;
  28. }
  29. }
  30. }