import Phaser from 'phaser'

class LoopEntity extends Phaser.GameObjects.Sprite {
  constructor (scene, x, y) {
    super(
      scene, x, y,
      'loop',
      0
    )
    this.startX = x
    this.setOrigin(0.2, 0.8)
  }

  show (cb) {
    this.alpha = 1
    return this.scene.tweens.add({
      targets: this,
      x: this.startX,
      duration: 1000,
      ease: 'Power0',
      onComplete: cb
    })
  }

  hide () {
    this.setScale(1)
    this.alpha = 0
    // return this.scene.tweens.add({
    //   targets: this,
    //   x: this.startX + this.width,
    //   duration: 1000,
    //   ease: 'Power0'
    // })
  }

  deathAnim (cb) {
    return this.scene.tweens.addCounter({
      from: 1,
      to: 8,
      duration: 2000,
      onUpdate: (tween) => {
        this.setScale(tween.getValue())
      },
      onComplete: cb
    })
  }
}

export default LoopEntity
