trinEntity.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. function TrinEntity() {
  2. TrinEntity.superclass.constructor.apply(this);
  3. this.x = 0;
  4. this.y = 0;
  5. this.width = 0;
  6. this.height = 0;
  7. this.orign = {x: 0, y: 0};
  8. this.bounds = new TrinRectangle(0, 0, 0, 0);
  9. this.boundsOffset = {left:0,top:0,right:0, bottom:0};
  10. this.scale = {x: 1, y: 1};
  11. }
  12. extend(TrinEntity, TrinBasic);
  13. TrinEntity.prototype.destroy = function() {
  14. TrinEntity.superclass.destroy.apply(this);
  15. this.orign = null;
  16. this.bounds = null;
  17. this.scale = null;
  18. };
  19. TrinEntity.prototype.update = function() {
  20. TrinEntity.superclass.update.apply(this);
  21. };
  22. TrinEntity.prototype.draw = function(context) {
  23. TrinEntity.superclass.draw.apply(this, [context]);
  24. };
  25. TrinEntity.prototype.kill = function() {
  26. TrinEntity.superclass.kill.apply(this);
  27. };
  28. TrinEntity.prototype.revive = function() {
  29. TrinEntity.superclass.revive.apply(this);
  30. };
  31. TrinEntity.prototype.hitTest = function(x, y) {
  32. TrinEntity.superclass.hitTest.apply(this);
  33. return this.bounds.intersects(x, y);
  34. };
  35. TrinEntity.prototype.updateBounds = function() {
  36. this.bounds.set(this.x - this.orign.x + this.boundsOffset.left,
  37. this.y - this.orign.y + this.boundsOffset.top,
  38. this.width - this.boundsOffset.right - this.boundsOffset.left,
  39. this.height - this.boundsOffset.bottom - this.boundsOffset.top);
  40. };
  41. TrinEntity.prototype.move = function(x, y) {
  42. this.reset(this.x + x, this.y + y);
  43. };
  44. TrinEntity.prototype.reset = function(x, y) {
  45. this.x = x;
  46. this.y = y;
  47. this.updateBounds();
  48. };