From 85146de39962a68e6ad4ca9c77c775d679a33540 Mon Sep 17 00:00:00 2001 From: Erik Onarheim Date: Sat, 8 Jun 2019 10:57:12 -0500 Subject: [PATCH] [bugfix] Release fixes and deprecations (#1164) --- CHANGELOG.md | 2 +- sandbox/src/game.ts | 15 ++--- sandbox/tests/anchors/anchors.ts | 105 ++++++++++++++--------------- sandbox/tests/debug/boundingbox.ts | 3 +- src/engine/Actions/Action.ts | 3 + src/engine/Actor.ts | 22 ++++-- src/engine/Collision/Body.ts | 4 ++ 7 files changed, 83 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 688b592b2..aad1dfc31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Breaking Changes - +- `ex.Actor.scale`, `ex.Actor.sx/sy`, `ex.Actor.actions.scaleTo/scaleBy` will not work as expected with new collider implementation, set width and height directly ### Added diff --git a/sandbox/src/game.ts b/sandbox/src/game.ts index fd7f9ec36..d27fc2afd 100644 --- a/sandbox/src/game.ts +++ b/sandbox/src/game.ts @@ -67,9 +67,10 @@ ex.Physics.acc = new ex.Vector(0, 800); // global accel // Add some UI //var heart = new ex.UIActor(0, 0, 20, 20); -var heart = new ex.UIActor({ x: 0, y: 0, width: 20, height: 20 }); -heart.scale.setTo(2, 2); -heart.addDrawing(heartTex.asSprite()); +var heart = new ex.UIActor({ x: 0, y: 0, width: 20 * 2, height: 20 * 2 }); +var heartSprite = heartTex.asSprite(); +heartSprite.scale.setTo(2, 2); +heart.addDrawing(heartSprite); game.add(heart); // Turn on debug diagnostics @@ -131,10 +132,6 @@ var label = new ex.Label({ y: 100, spriteFont: spriteFont }); -label.actions - .scaleTo(2, 2, 0.5, 0.5) - .scaleTo(1, 1, 0.5, 0.5) - .repeatForever(); game.add(label); // Retrieve animations for blocks from sprite sheet @@ -201,9 +198,8 @@ platform3.actions .repeatForever(); game.add(platform3); -var platform4 = new ex.Actor(200, 200, 100, 50, ex.Color.Azure); +var platform4 = new ex.Actor(75, 300, 100, 50, ex.Color.Azure); platform4.collisionType = ex.CollisionType.Fixed; -platform4.actions.moveBy(75, 300, 0.2); game.add(platform4); // Test follow api @@ -232,7 +228,6 @@ follower.actions // follow player -player.scale.setTo(1, 1); player.rotation = 0; // Health bar example diff --git a/sandbox/tests/anchors/anchors.ts b/sandbox/tests/anchors/anchors.ts index 1cad9392a..c62c7e5e3 100644 --- a/sandbox/tests/anchors/anchors.ts +++ b/sandbox/tests/anchors/anchors.ts @@ -32,16 +32,10 @@ game.setAntialiasing(false); // center anchored actors var cl = new ex.Label('Centered', 0, 30); cl.textAlign = ex.TextAlign.Center; -var ca1 = new ex.Actor(0, 0, 15, 15, ex.Color.Red); -var ca2 = new ex.Actor(0, 0, 10, 10, ex.Color.Green); -var ca3 = new ex.Actor(0, 0, 10, 10, ex.Color.Blue); -var ca4 = new ex.Actor(0, 0, 20, 20); -ca1.anchor.setTo(0.5, 0.5); -ca2.anchor.setTo(0.5, 0.5); -ca3.anchor.setTo(0.5, 0.5); -ca4.anchor.setTo(0.5, 0.5); -ca2.scale.setTo(2, 2); -ca4.scale.setTo(2, 2); +var ca1 = new ex.Actor({ x: 0, y: 0, width: 15, height: 15, color: ex.Color.Red, anchor: ex.Vector.Half }); +var ca2 = new ex.Actor({ x: 0, y: 0, width: 10 * 2, height: 10 * 2, color: ex.Color.Green, anchor: ex.Vector.Half }); +var ca3 = new ex.Actor({ x: 0, y: 0, width: 10, height: 10, color: ex.Color.Blue, anchor: ex.Vector.Half }); +var ca4 = new ex.Actor({ x: 0, y: 0, width: 20 * 2, height: 20 * 2, anchor: ex.Vector.Half }); var heartSprite = heartTx.asSprite(); heartSprite.scale.setTo(3, 3); ca4.addDrawing(heartSprite); @@ -57,18 +51,39 @@ game.add(cl); // top left anchored actors var tll = new ex.Label('Top Left', -100, -60); tll.textAlign = ex.TextAlign.Center; -var tla1 = new ex.Actor(-100, -100, 15, 15, ex.Color.Red); -var tla2 = new ex.Actor(-100, -100, 10, 10, ex.Color.Green); -var tla3 = new ex.Actor(-100, -100, 10, 10, ex.Color.Blue); -var tla4 = new ex.Actor(-100, -100, 20, 20); -tla1.anchor.setTo(0, 0); -tla2.anchor.setTo(0, 0); -tla3.anchor.setTo(0, 0); -tla4.anchor.setTo(0, 0); -tla2.scale.setTo(2, 2); -tla4.scale.setTo(2, 2); +var tla1 = new ex.Actor({ + x: -100, + y: -100, + width: 15, + height: 15, + color: ex.Color.Red, + anchor: ex.Vector.Zero +}); +var tla2 = new ex.Actor({ + x: -100, + y: -100, + width: 10 * 2, + height: 10 * 2, + color: ex.Color.Green, + anchor: ex.Vector.Zero +}); +var tla3 = new ex.Actor({ + x: -100, + y: -100, + width: 10, + height: 10, + color: ex.Color.Blue, + anchor: ex.Vector.Zero +}); +var tla4 = new ex.Actor({ + x: -100, + y: -100, + width: 20 * 2, + height: 20 * 2, + anchor: ex.Vector.Zero +}); var heartSprite2 = heartTx.asSprite(); -heartSprite2.scale.setTo(2, 2); +heartSprite2.scale.setTo(3, 3); tla4.addDrawing(heartSprite2); tla3.rotation = ex.Util.toRadians(45); @@ -81,17 +96,11 @@ game.add(tll); // top right anchored actors var trl = new ex.Label('Top Right', 100, -60); trl.textAlign = ex.TextAlign.Center; -var tra1 = new ex.Actor(100, -100, 15, 15, ex.Color.Red); -var tra2 = new ex.Actor(100, -100, 10, 10, ex.Color.Green); -var tra3 = new ex.Actor(100, -100, 10, 10, ex.Color.Blue); -var tra4 = new ex.Actor(100, -100, 20, 20); -tra1.anchor.setTo(1, 0); -tra2.anchor.setTo(1, 0); -tra3.anchor.setTo(1, 0); -tra4.anchor.setTo(1, 0); -tra2.scale.setTo(2, 2); -tra4.scale.setTo(2, 2); -tra4.addDrawing(heartTx); +var tra1 = new ex.Actor({ x: 100, y: -100, width: 15, height: 15, color: ex.Color.Red, anchor: new ex.Vector(1, 0) }); +var tra2 = new ex.Actor({ x: 100, y: -100, width: 10 * 2, height: 10 * 2, color: ex.Color.Green, anchor: new ex.Vector(1, 0) }); +var tra3 = new ex.Actor({ x: 100, y: -100, width: 10, height: 10, color: ex.Color.Blue, anchor: new ex.Vector(1, 0) }); +var tra4 = new ex.Actor({ x: 100, y: -100, width: 20 * 2, height: 20 * 2, anchor: new ex.Vector(1, 0) }); +tra4.addDrawing(heartSprite2); tra3.rotation = ex.Util.toRadians(45); game.add(tra4); @@ -103,17 +112,11 @@ game.add(trl); // bottom left anchored actors var bll = new ex.Label('Bottom Left', -100, 60); bll.textAlign = ex.TextAlign.Center; -var bla1 = new ex.Actor(-100, 100, 15, 15, ex.Color.Red); -var bla2 = new ex.Actor(-100, 100, 10, 10, ex.Color.Green); -var bla3 = new ex.Actor(-100, 100, 10, 10, ex.Color.Blue); -var bla4 = new ex.Actor(-100, 100, 20, 20); -bla1.anchor.setTo(0, 1); -bla2.anchor.setTo(0, 1); -bla3.anchor.setTo(0, 1); -bla4.anchor.setTo(0, 1); -bla2.scale.setTo(2, 2); -bla4.scale.setTo(2, 2); -bla4.addDrawing(heartTx); +var bla1 = new ex.Actor({ x: -100, y: 100, width: 15, height: 15, color: ex.Color.Red, anchor: new ex.Vector(0, 1) }); +var bla2 = new ex.Actor({ x: -100, y: 100, width: 10 * 2, height: 10 * 2, color: ex.Color.Green, anchor: new ex.Vector(0, 1) }); +var bla3 = new ex.Actor({ x: -100, y: 100, width: 10, height: 10, color: ex.Color.Blue, anchor: new ex.Vector(0, 1) }); +var bla4 = new ex.Actor({ x: -100, y: 100, width: 20 * 2, height: 20 * 2, anchor: new ex.Vector(0, 1) }); +bla4.addDrawing(heartSprite2); bla3.rotation = ex.Util.toRadians(45); game.add(bla4); @@ -125,17 +128,11 @@ game.add(bll); // bottom right anchored actors var brl = new ex.Label('Bottom Right', 100, 60); brl.textAlign = ex.TextAlign.Center; -var bra1 = new ex.Actor(100, 100, 15, 15, ex.Color.Red); -var bra2 = new ex.Actor(100, 100, 10, 10, ex.Color.Green); -var bra3 = new ex.Actor(100, 100, 10, 10, ex.Color.Blue); -var bra4 = new ex.Actor(100, 100, 20, 20); -bra1.anchor.setTo(1, 1); -bra2.anchor.setTo(1, 1); -bra3.anchor.setTo(1, 1); -bra4.anchor.setTo(1, 1); -bra2.scale.setTo(2, 2); -bra4.scale.setTo(2, 2); -bra4.addDrawing(heartTx); +var bra1 = new ex.Actor({ x: 100, y: 100, width: 15, height: 15, color: ex.Color.Red, anchor: new ex.Vector(1, 1) }); +var bra2 = new ex.Actor({ x: 100, y: 100, width: 10 * 2, height: 10 * 2, color: ex.Color.Green, anchor: new ex.Vector(1, 1) }); +var bra3 = new ex.Actor({ x: 100, y: 100, width: 10, height: 10, color: ex.Color.Blue, anchor: new ex.Vector(1, 1) }); +var bra4 = new ex.Actor({ x: 100, y: 100, width: 20 * 2, height: 20 * 2, anchor: new ex.Vector(1, 1) }); +bra4.addDrawing(heartSprite2); bra3.rotation = ex.Util.toRadians(45); game.add(bra4); diff --git a/sandbox/tests/debug/boundingbox.ts b/sandbox/tests/debug/boundingbox.ts index be428c872..71bd38b5e 100644 --- a/sandbox/tests/debug/boundingbox.ts +++ b/sandbox/tests/debug/boundingbox.ts @@ -5,9 +5,8 @@ var game = new ex.Engine({ width: 500, height: 500 }); game.isDebug = true; game.start().then(() => { - var parent = new ex.Actor(100, 100, 100, 100, ex.Color.Red); + var parent = new ex.Actor(100, 100, 100 * 1.5, 100 * 1.5, ex.Color.Red); var child = new ex.Actor(150, 150, 100, 100, ex.Color.White); - parent.scale.setTo(1.5, 1.5); parent.add(child); game.add(parent); }); diff --git a/src/engine/Actions/Action.ts b/src/engine/Actions/Action.ts index 9114fa66b..ddd861205 100644 --- a/src/engine/Actions/Action.ts +++ b/src/engine/Actions/Action.ts @@ -4,6 +4,7 @@ import { Actor } from '../Actor'; import { Vector } from '../Algebra'; import { Logger } from '../Util/Log'; import * as Util from '../Util/Util'; +import { obsolete } from '../Util/Decorators'; /** * Used for implementing actions for the [[ActionContext|Action API]]. @@ -543,6 +544,7 @@ export class RotateBy implements Action { } } +@obsolete({ message: 'ex.Action.ScaleTo will be removed in v0.24.0', alternateMethod: 'Set width and hight directly' }) export class ScaleTo implements Action { private _actor: Actor; public x: number; @@ -614,6 +616,7 @@ export class ScaleTo implements Action { } } +@obsolete({ message: 'ex.Action.ScaleBy will be removed in v0.24.0', alternateMethod: 'Set width and hight directly' }) export class ScaleBy implements Action { private _actor: Actor; public x: number; diff --git a/src/engine/Actor.ts b/src/engine/Actor.ts index d342d74ac..961663c72 100644 --- a/src/engine/Actor.ts +++ b/src/engine/Actor.ts @@ -382,6 +382,7 @@ export class ActorImpl extends Class implements Actionable, Eventable, PointerEv /** * Gets the scale vector of the actor + * @obsolete ex.Actor.scale will be removed in v0.24.0, set width and height directly in constructor */ public get scale(): Vector { return this.body.scale; @@ -389,6 +390,7 @@ export class ActorImpl extends Class implements Actionable, Eventable, PointerEv /** * Sets the scale vector of the actor for + * @obsolete ex.Actor.scale will be removed in v0.24.0, set width and height directly in constructor */ public set scale(scale: Vector) { this.body.scale = scale; @@ -396,6 +398,7 @@ export class ActorImpl extends Class implements Actionable, Eventable, PointerEv /** * Gets the old scale of the actor last frame + * @obsolete ex.Actor.scale will be removed in v0.24.0, set width and height directly in constructor */ public get oldScale(): Vector { return this.body.oldScale; @@ -403,6 +406,7 @@ export class ActorImpl extends Class implements Actionable, Eventable, PointerEv /** * Sets the the old scale of the acotr last frame + * @obsolete ex.Actor.scale will be removed in v0.24.0, set width and height directly in constructor */ public set oldScale(scale: Vector) { this.body.oldScale = scale; @@ -410,6 +414,7 @@ export class ActorImpl extends Class implements Actionable, Eventable, PointerEv /** * Gets the x scalar velocity of the actor in scale/second + * @obsolete ex.Actor.sx will be removed in v0.24.0, set width and height directly in constructor */ public get sx(): number { return this.body.sx; @@ -417,13 +422,16 @@ export class ActorImpl extends Class implements Actionable, Eventable, PointerEv /** * Sets the x scalar velocity of the actor in scale/second + * @obsolete ex.Actor.sx will be removed in v0.24.0, set width and height directly in constructor */ + @obsolete({ message: 'ex.Actor.sx will be removed in v0.24.0', alternateMethod: 'Set width and height directly in constructor' }) public set sx(scalePerSecondX: number) { this.body.sx = scalePerSecondX; } /** * Gets the y scalar velocity of the actor in scale/second + * @obsolete ex.Actor.sy will be removed in v0.24.0, set width and height directly in constructor */ public get sy(): number { return this.body.sy; @@ -431,7 +439,9 @@ export class ActorImpl extends Class implements Actionable, Eventable, PointerEv /** * Sets the y scale velocity of the actor in scale/second + * @obsolete ex.Actor.sy will be removed in v0.24.0, set width and height directly in constructor */ + @obsolete({ message: 'ex.Actor.sy will be removed in v0.24.0', alternateMethod: 'Set width and height directly in constructor' }) public set sy(scalePerSecondY: number) { this.body.sy = scalePerSecondY; } @@ -567,6 +577,9 @@ export class ActorImpl extends Class implements Actionable, Eventable, PointerEv constructor(xOrConfig?: number | ActorArgs, y?: number, width?: number, height?: number, color?: Color) { super(); + // initialize default options + this._initDefaults(); + let shouldInitializeBody = true; if (xOrConfig && typeof xOrConfig === 'object') { const config = xOrConfig; @@ -579,10 +592,11 @@ export class ActorImpl extends Class implements Actionable, Eventable, PointerEv shouldInitializeBody = false; this.body = config.body; } - } - // initialize default options - this._initDefaults(); + if (config.anchor) { + this.anchor = config.anchor; + } + } // Body and collider bounds are still determined by actor width/height this._width = width || 0; @@ -1633,7 +1647,7 @@ export class ActorImpl extends Class implements Actionable, Eventable, PointerEv this.body.collider.debugDraw(ctx); // Draw actor bounding box - const bb = this.body.collider.bounds; + const bb = this.body.collider.localBounds.translate(this.getWorldPos()); bb.debugDraw(ctx); // Draw actor Id diff --git a/src/engine/Collision/Body.ts b/src/engine/Collision/Body.ts index f45688255..271e39def 100644 --- a/src/engine/Collision/Body.ts +++ b/src/engine/Collision/Body.ts @@ -131,20 +131,24 @@ export class Body implements Clonable { /** * The scale vector of the actor + * @obsolete ex.Body.scale will be removed in v0.24.0 */ public scale: Vector = Vector.One; /** * The scale of the actor last frame + * @obsolete ex.Body.scale will be removed in v0.24.0 */ public oldScale: Vector = Vector.One; /** * The x scalar velocity of the actor in scale/second + * @obsolete ex.Body.scale will be removed in v0.24.0 */ public sx: number = 0; //scale/sec /** * The y scalar velocity of the actor in scale/second + * @obsolete ex.Body.scale will be removed in v0.24.0 */ public sy: number = 0; //scale/sec