Sprite2D.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /************************************************************************
  2. * Sprite2D.js
  3. ************************************************************************
  4. * Copyright (c) 2021 Pedro Tonini Rosenberg Schneider.
  5. *
  6. * This file is part of Pandora.
  7. *
  8. * Pandora is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Pandora is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Pandora. If not, see <https://www.gnu.org/licenses/>.
  20. *************************************************************************/
  21. class Sprite2D extends Object2D
  22. {
  23. constructor(name, p5Image)
  24. {
  25. super(name);
  26. this.P5Image = p5Image;
  27. }
  28. draw(delta)
  29. {
  30. push();
  31. translate(this.position.x, this.position.y);
  32. rotate(this.rotationDegrees);
  33. scale(this.scale.x, this.scale.y);
  34. image(this.P5Image, 0, 0, this.P5Image.width, this.P5Image.height);
  35. this._draw(delta);
  36. for (let i = 0; i < this.children.length; i++)
  37. this.children[i].draw(delta);
  38. pop()
  39. }
  40. }