|
@@ -48,6 +48,10 @@ class Object2D extends GameObject
|
|
|
this.rotationDegrees = 0;
|
|
|
this.scale = Vector2.ONE();
|
|
|
this.visible = true;
|
|
|
+
|
|
|
+ this.globalPosition = Vector2.ZERO();
|
|
|
+ this.globalRotationDegrees = 0;
|
|
|
+ this.globalScale = Vector2.ONE();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -119,6 +123,40 @@ class Object2D extends GameObject
|
|
|
return this.visible;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Updates this Object2D's global transform and recursively calls the _update(delta)
|
|
|
+ * callback for this GameObject and all of it's children.
|
|
|
+ *
|
|
|
+ * @param {number} delta number of ellapsed seconds since the last frame.
|
|
|
+ *
|
|
|
+ * @override
|
|
|
+ */
|
|
|
+ update(delta)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (!this.parented || !(this.parent instanceof Object2D))
|
|
|
+ {
|
|
|
+ this.globalPosition = this.position;
|
|
|
+ this.globalRotationDegrees = this.rotationDegrees;
|
|
|
+ this.globalScale = this.globalScale;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ this.globalPosition.x = this.parent.globalPosition.x + this.position.x;
|
|
|
+ this.globalPosition.y = this.parent.globalPosition.y + this.position.y;
|
|
|
+ this.globalRotationDegrees = this.parent.globalRotationDegrees + this.rotationDegrees;
|
|
|
+ this.globalScale.x = this.parent.globalScale.x + this.scale.x;
|
|
|
+ this.globalScale.y = this.parent.globalScale.y + this.scale.y;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ this._update(delta);
|
|
|
+ for (let i = 0; i < this.children.length; i++)
|
|
|
+ {
|
|
|
+ this.children[i].update(delta);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* Applies this Object2D's transform before calling this GameObject's _draw() callback
|
|
|
* and recursively calls the same callback on all of it's children. This results in the
|