import CollisionDetection from "./CollisionDetection"; import MapConroler from "./Map"; const {ccclass, property} = cc._decorator; @ccclass export default class Block extends cc.Component { // 新增缓存变量 private selfBoxColliders: cc.BoxCollider[] = []; private allBoxColliders: cc.BoxCollider[] = []; // @property({ // tooltip: '碰撞形状,None就是无敌,不参与碰撞', // type: cc.Enum(BlockType), // // default: BlockType.Nomal, // displayName: '碰撞形状' // }) // LIFE-CYCLE CALLBACKS: // @property(cc.SpriteAtlas) // UI: cc.SpriteAtlas = null; private initialTouchOffset: cc.Vec2 = null; private offsetTolerance = 100; // 偏移容忍度; allBlocks:any; //所有的方块,用于计算posX,posY消除 touchPoint: cc.Vec2 = null; //触摸点 isTouch: boolean = false; //是否触摸 posX: number = 0; //地图块的X坐标 posY: number = 0; //地图块的Y坐标 moveLeft: boolean = true; //是否可以左移; moveRight: boolean = true; //是否可以右移; moveUp: boolean = true; //是否可以上移; moveDown: boolean = true; //是否可以下移; moveCorner: number = 0; //是否碰撞角落 moveY:number = 0; //是否可以上下移动; moveX:number = 0; //是否可以左右移动; touchPointX: number = 0; //触摸点X坐标; touchPointY: number = 0; //触摸点Y坐标; blockId: number = 0; //方块ID; stacking: cc.Vec2; //叠加方块 level: number = 0; //叠加方块层数; pz: boolean = false; collider: any; block_Info:any; _touchListener: any; relative_Position:cc.Vec2; //点击和方块相对位置 private _eventManager: any; hit: cc.Node; onLoad () { // this.node.on(cc.Node.EventType.TOUCH_START, this.touchStart, this); // this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this); // this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd, this); // this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd, this); this.pz = false; this.stacking = cc.v2(0,0); // this.selfBoxColliders = this.node.getComponentsInChildren(cc.BoxCollider) // .filter(collider => collider.tag < 4); } start () { } jsonDeepClone(obj: T): T { return JSON.parse(JSON.stringify(obj)); } init(block_Info,posX,posY,node){ this.block_Info = this.jsonDeepClone(block_Info); let mapInfo = MapConroler._instance.mapInfo; for(let i=0; i