taskPrefabHighway.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. highwayParent: {
  14. default: null,
  15. type: cc.Node,
  16. serializable: true,
  17. },
  18. highwayPrefab: {
  19. default: null,
  20. type: cc.Node,
  21. serializable: true,
  22. },
  23. },
  24. // LIFE-CYCLE CALLBACKS:
  25. // onLoad () {},
  26. start() {
  27. let _startPos = GlobalD.TiledMap._tilePosFromLocation(this.node.getPosition());
  28. this.onSetHighway(_startPos, true, 4);
  29. },
  30. //设置提示建筑的道路
  31. onSetHighway(_startTiledtile, _isAxisX, _length) {
  32. for (let i = 0; i < _length; i++) {
  33. let highwayTemp = null;
  34. highwayTemp = cc.instantiate(this.highwayPrefab);
  35. //设置半透明
  36. highwayTemp.opacity = 100;
  37. highwayTemp.active = true;
  38. highwayTemp.parent = this.highwayParent;
  39. let tiledTile = highwayTemp.addComponent('TiledTile');
  40. if (_isAxisX) {
  41. tiledTile.x = _startTiledtile.x + i;
  42. tiledTile.y = _startTiledtile.y;
  43. } else {
  44. tiledTile.x = _startTiledtile.x;
  45. tiledTile.y = _startTiledtile.y + i;
  46. }
  47. //记录终点的坐标
  48. if (i == _length - 1) {
  49. task.virtualShadowPosEnd = cc.v2(tiledTile.x, tiledTile.y);
  50. }
  51. }
  52. },
  53. });