button.js 521 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * 一个Button基础类
  3. *
  4. * @export
  5. * @class Button
  6. */
  7. export default class Button {
  8. constructor(src, x, y, width, height) {
  9. this.img = new Image()
  10. this.img.src = src
  11. this.x = x
  12. this.y = y
  13. this.height = height
  14. this.width = width
  15. }
  16. render(ctx) {
  17. ctx.drawImage(this.img, this.x, this.y, this.width, this.height)
  18. }
  19. isTapped(x, y) {
  20. if (x > this.x && x < (this.x + this.width) && y > this.y && y < (this.y + this.height)) {
  21. return true
  22. }
  23. return false
  24. }
  25. }