TiledTile.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // 根据x和y 来设置图块位置
  2. // Map下的点为父节点
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. x: {
  7. // ATTRIBUTES:
  8. default: 0, // The default value will be used only when the component attaching
  9. // to a node for the first time
  10. type: cc.Integer, // optional, default is typeof default
  11. serializable: true, // optional, default is true
  12. },
  13. y: {
  14. // ATTRIBUTES:
  15. default: 0, // The default value will be used only when the component attaching
  16. // to a node for the first time
  17. type: cc.Integer, // optional, default is typeof default
  18. serializable: true, // optional, default is true
  19. },
  20. },
  21. // LIFE-CYCLE CALLBACKS:
  22. // onLoad () {},
  23. start() {
  24. this.setTiledTilePos(this.x, this.y);
  25. },
  26. //根据x y 坐标设置TiledTile位置
  27. setTiledTilePos(_x, _y) {
  28. this.x = _x;
  29. this.y = _y;
  30. let location = GlobalD.TiledMap._locationFromtilePos(cc.v2(this.x, this.y));
  31. location = this.node.parent.convertToNodeSpaceAR(location);
  32. //我们计算的点事顶点为起始点,所以y轴要减去图块的一半。
  33. let CanvasPos = GlobalD.game.Canvas.position;
  34. let endLocation = cc.v2(location.x + CanvasPos.x, location.y + CanvasPos.y - 48);
  35. this.node.setPosition(endLocation);
  36. }
  37. // update (dt) {},
  38. });