| | |
| | | activateMapEvent = (leftEvent, rightEvent) => { |
| | | if (this.mapEvent) { |
| | | this.mapContainer.parent.off('mousedown', this.mapEvent); |
| | | this.mapEvent = null; |
| | | } |
| | | this.mapEvent = (event) => { |
| | | // left |
| | |
| | | isSelecting = false; |
| | | selectionBox.clear(); |
| | | |
| | | |
| | | // batch move |
| | | if (this.selectedSprites && this.selectedSprites.length > 0) { |
| | | this.batchMove = false; |
| | | |
| | | const batchMoving = (event) => { |
| | | if (this.batchMove) { |
| | | var mouseMovement = { x: event.global.x - this.batchMoveStartPos.x, y: event.global.y - this.batchMoveStartPos.y }; |
| | | for (let sprite of this.selectedSprites) { |
| | | sprite.position.x = sprite.data.batchMoveStartPos.x + mouseMovement.x; |
| | | sprite.position.y = sprite.data.batchMoveStartPos.y + mouseMovement.y; |
| | | } |
| | | } |
| | | } |
| | | |
| | | const batchMoveEnd = (event) => { |
| | | this.selectedSprites.forEach(child => { |
| | | Utils.unMarkSprite(child); |
| | | }) |
| | | this.selectedSprites = []; |
| | | this.mapContainer.parent.off('mousedown'); |
| | | this.mapContainer.parent.off('mousemove'); |
| | | |
| | | this.activateMapEvent(Utils.MapEvent.SELECTION_BOX); |
| | | } |
| | | |
| | | const batchMoveStart = (event) => { |
| | | this.batchMoveStartPos = { x: event.data.global.clone().x, y: event.data.global.clone().y }; |
| | | this.selectedSprites.forEach(child => { |
| | | child.data.batchMoveStartPos = { x: child.position.x, y: child.position.y }; |
| | | }) |
| | | |
| | | this.batchMove = true; |
| | | this.mapContainer.parent.off('mousemove'); |
| | | this.mapContainer.parent.on('mousemove', batchMoving); |
| | | |
| | | this.mapContainer.parent.off('mouseup'); |
| | | this.mapContainer.parent.on('mouseup', batchMoveEnd); |
| | | } |
| | | |
| | | this.mapContainer.parent.off('mousedown') |
| | | this.mapContainer.parent.on('mousedown', batchMoveStart); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | this.mapContainer.parent.off('mousemove', handleMouseMove); |