trinGroup.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. function TrinGroup(width, height) {
  2. TrinGroup.superclass.constructor.apply(this);
  3. this.canvas = document.createElement("canvas");
  4. this.canvas.width = width;
  5. this.canvas.height = height;
  6. this.context = this.canvas.getContext("2d");
  7. this.group = new TrinLayer();
  8. this.width = width;
  9. this.height = height;
  10. this.updateBounds();
  11. }
  12. extend(TrinGroup, TrinEntity);
  13. TrinGroup.prototype.add = function(entity) {
  14. this.group.add(entity);
  15. };
  16. TrinGroup.prototype.remove = function(entity) {
  17. this.group.remove(entity);
  18. };
  19. TrinGroup.prototype.draw = function(context) {
  20. TrinGroup.superclass.draw.apply(this, [context]);
  21. this.context.clearRect(0, 0, this.width, this.height);
  22. this.group.draw(this.context);
  23. var sx = 0;
  24. var sy = 0;
  25. var sw = this.width;
  26. var sh = this.height;
  27. var dx = this.x - this.orign.x * this.scale.x;
  28. var dy = this.y - this.orign.y * this.scale.y;
  29. var dw = this.width * this.scale.x;
  30. var dh = this.height * this.scale.y;
  31. context.drawImage(this.canvas, sx, sy, sw, sh, dx, dy, dw, dh);
  32. };