| | |
| | | |
| | | // func |
| | | this.app.view.addEventListener('mousedown', (event) => { |
| | | // 右键 |
| | | // left |
| | | if (event.button === 0) { |
| | | this.mapSelect(event); |
| | | } |
| | | // right |
| | | if (event.button === 2) { |
| | | this.mapPan(event); |
| | | } |
| | |
| | | this.appTicker(); |
| | | } |
| | | |
| | | mapSelect = (event) => { |
| | | let isSelecting = false; |
| | | |
| | | const selectionBox = new PIXI.Graphics(); |
| | | this.app.stage.addChild(selectionBox); |
| | | |
| | | // start |
| | | const startPoint = new PIXI.Point(); |
| | | this.app.renderer.events.mapPositionToPoint(startPoint, event.clientX, event.clientY); |
| | | let selectionStart = { x: startPoint.x, y: startPoint.y }; |
| | | |
| | | isSelecting = true; |
| | | |
| | | this.app.view.addEventListener('mousemove', (event) => { |
| | | console.log(1); |
| | | if (isSelecting) { |
| | | |
| | | // end |
| | | const endPoint = new PIXI.Point(); |
| | | this.app.renderer.events.mapPositionToPoint(endPoint, event.clientX, event.clientY); |
| | | const selectionEnd = { x: endPoint.x, y: endPoint.y } |
| | | |
| | | const width = Math.abs(selectionEnd.x - selectionStart.x); |
| | | const height = Math.abs(selectionEnd.y - selectionStart.y); |
| | | |
| | | selectionBox.clear(); |
| | | selectionBox.lineStyle(2, 0xCCCCCC, 1); |
| | | selectionBox.beginFill(0xCCCCCC, 0.2); |
| | | selectionBox.drawRect(Math.min(selectionStart.x, selectionEnd.x), Math.min(selectionStart.y, selectionEnd.y), width, height); |
| | | selectionBox.endFill(); |
| | | } |
| | | }); |
| | | |
| | | this.app.view.addEventListener('mouseup', (event) => { |
| | | if (isSelecting) { |
| | | isSelecting = false; |
| | | selectionBox.clear(); |
| | | |
| | | // const selectedSprites = this.mapContainer.children.filter(sprite => { |
| | | // const spriteBounds = sprite.getBounds(); |
| | | // const boxBounds = new PIXI.Rectangle(Math.min(selectionStart.x, event.clientX), Math.min(selectionStart.y, event.clientY), Math.abs(event.clientX - selectionStart.x), Math.abs(event.clientY - selectionStart.y)); |
| | | // return spriteBounds.contains(boxBounds.x, boxBounds.y) && spriteBounds.contains(boxBounds.x + boxBounds.width, boxBounds.y + boxBounds.height); |
| | | // }); |
| | | |
| | | // console.log('Selected Sprites:', selectedSprites); |
| | | } |
| | | |
| | | this.app.view.removeEventListener('mousemove'); |
| | | }); |
| | | } |
| | | |
| | | activateMapScale = () => { |
| | | this.app.view.addEventListener('wheel', (event) => { |
| | | event.preventDefault(); |