| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- // 根据x和y 来设置图块位置
- // Map下的点为父节点
- cc.Class({
- extends: cc.Component,
- properties: {
- x: {
- // ATTRIBUTES:
- default: 0, // The default value will be used only when the component attaching
- // to a node for the first time
- type: cc.Integer, // optional, default is typeof default
- serializable: true, // optional, default is true
- },
- y: {
- // ATTRIBUTES:
- default: 0, // The default value will be used only when the component attaching
- // to a node for the first time
- type: cc.Integer, // optional, default is typeof default
- serializable: true, // optional, default is true
- },
- },
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {},
- start() {
- this.setTiledTilePos(this.x, this.y);
- },
- //根据x y 坐标设置TiledTile位置
- setTiledTilePos(_x, _y) {
- this.x = _x;
- this.y = _y;
- let location = GlobalD.TiledMap._locationFromtilePos(cc.v2(this.x, this.y));
- location = this.node.parent.convertToNodeSpaceAR(location);
- //我们计算的点事顶点为起始点,所以y轴要减去图块的一半。
- let CanvasPos = GlobalD.game.Canvas.position;
- let endLocation = cc.v2(location.x + CanvasPos.x, location.y + CanvasPos.y - 48);
- this.node.setPosition(endLocation);
- }
- // update (dt) {},
- });
|