import { Physics } from 'phaser'; export class Magnet extends Physics.Arcade.Sprite { constructor(scene, x, y) { super(scene, x, y, 'magnet'); scene.add.existing(this); scene.physics.add.existing(this, true); this.setScale(0.8); this.body.setSize(this.width * 0.8, this.height * 0.8); this.body.setOffset(this.width * 0.1, this.height * 0.1); this.consumed = false; this.floatTween = scene.tweens.add({ targets: this, y: y - 6, duration: 700, yoyo: true, repeat: -1, ease: 'Sine.easeInOut', }); } onPlayerTouch(player) { if (this.consumed) return false; this.consumed = true; this.body.enable = false; this.setVisible(false); player.startMagnet(); this.destroy(); return true; } destroy(fromScene) { if (this.floatTween) { this.floatTween.stop(); this.floatTween = null; } super.destroy(fromScene); } }