Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy #1241

Closed
wants to merge 2 commits into from
Closed

Proxy #1241

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions packages/melonjs/src/camera/camera2d.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Vector2d from "./../math/vector2.js";
import Vector3d from "./../math/vector3.js";
import ObservableVector2d from "./../math/observable_vector2.js";
import ObservableVector3d from "./../math/observable_vector3.js";
import Matrix2d from "./../math/matrix2.js";
import Matrix3d from "./../math/matrix3.js";
import Rect from "./../geometries/rectangle.js";
Expand Down Expand Up @@ -322,12 +320,7 @@ export default class Camera2d extends Renderable {
follow(target, axis, damping) {
if (target instanceof Renderable) {
this.target = target.pos;
} else if (
target instanceof Vector2d ||
target instanceof Vector3d ||
target instanceof ObservableVector2d ||
target instanceof ObservableVector3d
) {
} else if (target instanceof Vector2d || target instanceof Vector3d) {
this.target = target;
} else {
throw new Error("invalid target for me.Camera2d.follow");
Expand Down
6 changes: 3 additions & 3 deletions packages/melonjs/src/geometries/ellipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import pool from "./../system/pooling.js";

/**
* additional import for TypeScript
* @import Vector2d from "./../math/vector2.js";
* @import Vector3d from "./../math/vector3.js";
* @import Matrix2d from "./../math/matrix2.js";
* @import Bounds from "./../physics/bounds.js";
*/
Expand All @@ -21,9 +21,9 @@ export default class Ellipse {
/**
* the center coordinates of the ellipse
* @public
* @type {Vector2d}
* @type {Vector3d}
*/
this.pos = pool.pull("Vector2d");
this.pos = pool.pull("Vector3d");

/**
* The bounding rectangle for this shape
Expand Down
28 changes: 22 additions & 6 deletions packages/melonjs/src/geometries/poly.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { earcut } from "./earcut.js";

/**
* additional import for TypeScript
* @import Vector2d from "./../math/vector2.js";
* @import Vector3d from "./../math/vector3.js";
* @import Matrix2d from "./../math/matrix2.js";
* @import Bounds from "./../physics/bounds.js";
*/
Expand All @@ -25,9 +25,27 @@ export default class Polygon {
constructor(x = 0, y = 0, points) {
/**
* origin point of the Polygon
* @type {Vector2d}
* @type {Vector3}
*/
this.pos = pool.pull("Vector2d");
this.pos = pool.pull("Vector3d");
/**
* Proxy to the pos Vector3d object
* @ignore
*/
this.posProxy = new Proxy(this.pos, {
set: (obj, prop, value) => {
// only update bounds if x or y has changed (ignore z)
if (prop !== "z") {
const newX = prop === "x" ? value : obj.x;
const newY = prop === "y" ? value : obj.y;
this.getBounds().translate(newX - obj.x, newY - obj.y);
}

obj[prop] = value;

return true;
},
});

/**
* Array of points defining the Polygon <br>
Expand Down Expand Up @@ -86,8 +104,8 @@ export default class Polygon {
* @returns {Polygon} this instance for objecf chaining
*/
setShape(x, y, points) {
this.pos.set(x, y);
this.setVertices(points);
this.pos.set(x, y);
return this;
}

Expand Down Expand Up @@ -334,7 +352,6 @@ export default class Polygon {

this.pos.x += _x;
this.pos.y += _y;
this.getBounds().translate(_x, _y);

return this;
}
Expand Down Expand Up @@ -362,7 +379,6 @@ export default class Polygon {
}
this.pos.x = _x;
this.pos.y = _y;
this.updateBounds();
}

/**
Expand Down
8 changes: 0 additions & 8 deletions packages/melonjs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import "./polyfill/index.ts";
import Color from "./math/color.js";
import Vector2d from "./math/vector2.js";
import Vector3d from "./math/vector3.js";
import ObservableVector2d from "./math/observable_vector2.js";
import ObservableVector3d from "./math/observable_vector3.js";
import Matrix2d from "./math/matrix2.js";
import Matrix3d from "./math/matrix3.js";
import Polygon from "./geometries/poly.js";
Expand Down Expand Up @@ -101,8 +99,6 @@ export {
Color,
Vector2d,
Vector3d,
ObservableVector2d,
ObservableVector3d,
Matrix2d,
Matrix3d,
Polygon,
Expand Down Expand Up @@ -228,8 +224,6 @@ export function boot() {
pool.register("me.ColorLayer", ColorLayer, true);
pool.register("me.Vector2d", Vector2d, true);
pool.register("me.Vector3d", Vector3d, true);
pool.register("me.ObservableVector2d", ObservableVector2d, true);
pool.register("me.ObservableVector3d", ObservableVector3d, true);
pool.register("me.Matrix2d", Matrix2d, true);
pool.register("me.Matrix3d", Matrix3d, true);
pool.register("me.Rect", Rect, true);
Expand Down Expand Up @@ -258,8 +252,6 @@ export function boot() {
pool.register("ColorLayer", ColorLayer, true);
pool.register("Vector2d", Vector2d, true);
pool.register("Vector3d", Vector3d, true);
pool.register("ObservableVector2d", ObservableVector2d, true);
pool.register("ObservableVector3d", ObservableVector3d, true);
pool.register("Matrix2d", Matrix2d, true);
pool.register("Matrix3d", Matrix3d, true);
pool.register("Rect", Rect, true);
Expand Down
2 changes: 1 addition & 1 deletion packages/melonjs/src/level/tiled/TMXTileMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ export default class TMXTileMap {
obj.body = new Body(obj, shape);
obj.body.setStatic(true);
// set the obj z order
obj.pos.setMuted(settings.x, settings.y, settings.z);
obj.pos.set(settings.x, settings.y, settings.z);
} else {
// pull the corresponding object from the object pool
if (typeof settings.name !== "undefined" && settings.name !== "") {
Expand Down
Loading
Loading