TextPop.js 863 B

123456789101112131415161718192021222324252627282930313233
  1. import { Point } from "../spatial/Point.js";
  2. import { Easing, Tween } from "../Tween.js";
  3. import { Theme } from "../../libraries/components/Theme.js"
  4. export class TextPop {
  5. constructor(tweenManager, text, pos, startDelay) {
  6. this.tweenManager = tweenManager
  7. this.position = pos
  8. this.alpha = 0
  9. this.text = text
  10. this.isCompleted = false
  11. setTimeout(() => {
  12. this.alpha = 1
  13. this.tweenManager.add(new Tween(this, { position: { y: this.position.y - 60 }, alpha: 0 }, 1000, Easing.Linear.EaseNone, () => {
  14. this.isCompleted = true
  15. }))
  16. }, startDelay)
  17. }
  18. draw(ctx, scaledCanvas) {
  19. ctx.fillStyle = Theme.Colors.darkgreen.replace(")", `,${this.alpha})`)
  20. ctx.font = `36px Arial`
  21. ctx.textAlign = "center"
  22. ctx.save()
  23. ctx.translate(this.position.x, this.position.y)
  24. ctx.fillText(this.text, 0, 0)
  25. ctx.restore()
  26. }
  27. update(delta) {
  28. }
  29. }