소스 검색

✨ Add some transformation methods to Object2D

Pedro Schneider 3 년 전
부모
커밋
888e141551
2개의 변경된 파일35개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      pandora.min.js
  2. 34 0
      pandora/game_objects/2d_objects/Object2D.js

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 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.