Browse Source

✨ Add some transformation methods to Object2D

Pedro Schneider 3 years ago
parent
commit
888e141551
2 changed files with 35 additions and 1 deletions
  1. 1 1
      pandora.min.js
  2. 34 0
      pandora/game_objects/2d_objects/Object2D.js

File diff suppressed because it is too large
+ 1 - 1
pandora.min.js


+ 34 - 0
pandora/game_objects/2d_objects/Object2D.js

@@ -123,6 +123,40 @@ class Object2D extends GameObject
         return this.visible;
     }
 
+    /**
+     * Translates this Object2D by (x, y).
+     * 
+     * @param {number} x    X-axis translation. 
+     * @param {number} y    Y-axis translation.
+     */
+    translate(x, y)
+    {
+        this.position.x += x;
+        this.position.y += y;
+    }
+    
+    /**
+     * Rotates this Object2D by a degrees.
+     * 
+     * @param {number} a    rotation in degrees. 
+     */
+    rotate(a)
+    {
+        this.rotationDegrees += a;
+    }
+
+    /**
+     * Scales this Object2D by (x, y).
+     * 
+     * @param {number} x    X-axis scale.
+     * @param {number} y    Y-axis scale.
+     */
+    addScale(x, y)
+    {
+        this.scale.x *= x;
+        this.scale.y *= y;
+    }
+
     /**
      * Updates this Object2D's global transform and recursively calls the _update(delta)
      * callback for this GameObject and all of it's children.