Object2D.js 997 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. /**
  3. * Base 2D object class, implements all the object positioning and scalling features.
  4. *
  5. * @class
  6. */
  7. function Object2D()
  8. {
  9. /**
  10. * UUID of the object.
  11. */
  12. this.uuid = UUID.generate();
  13. /**
  14. * List of children objects attached to the object.
  15. */
  16. this.children = [];
  17. /**
  18. * Parent object, the object position is affected by its parent position.
  19. */
  20. this.parent = null;
  21. /**
  22. * Position of the object.
  23. */
  24. this.position = new Vector2(0, 0);
  25. /**
  26. * Scale of the object.
  27. */
  28. this.scale = new Vector2(1, 1);
  29. /**
  30. * Rotation of the object relative to its center.
  31. */
  32. this.rotation = 0.0;
  33. /**
  34. * Local transformation matrix applied to the object.
  35. */
  36. this.matrix = new Matrix3();
  37. /**
  38. * Global transformation matrix used to project the object to screen space.
  39. */
  40. this.globalMatrix = new Matrix3();
  41. }
  42. /**
  43. * Attach a children to the object.
  44. */
  45. Object2D.prototype.add = function(object)
  46. {
  47. object.parent = this;
  48. this.children.push(object);
  49. };