Sprite2D.js 632 B

123456789101112131415161718192021222324252627
  1. class Sprite2D extends Object2D
  2. {
  3. constructor(name, p5Image)
  4. {
  5. super(name);
  6. if (p5Image)
  7. this.texture = new Texture(p5Image, p5Image.width, p5Image.height);
  8. }
  9. draw(delta)
  10. {
  11. push();
  12. translate(this.position.x, this.position.y);
  13. rotate(this.rotationDegrees);
  14. scale(this.scale.x, this.scale.y);
  15. image(this.texture.image, this.position.x, this.position.y, this.texture.width, this.texture.height);
  16. this._draw(delta);
  17. for (let i = 0; i < this.children.length; i++)
  18. this.children[i].draw(delta);
  19. pop()
  20. }
  21. }