Skip to content

Commit

Permalink
[bugfix] Release fixes and deprecations (#1164)
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim authored Jun 8, 2019
1 parent 1e79034 commit 85146de
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 71 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Breaking Changes

<!--- Breaking changes here --->
- `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

Expand Down
15 changes: 5 additions & 10 deletions sandbox/src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -232,7 +228,6 @@ follower.actions

// follow player

player.scale.setTo(1, 1);
player.rotation = 0;

// Health bar example
Expand Down
105 changes: 51 additions & 54 deletions sandbox/tests/anchors/anchors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions sandbox/tests/debug/boundingbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
3 changes: 3 additions & 0 deletions src/engine/Actions/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]].
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 18 additions & 4 deletions src/engine/Actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,56 +382,66 @@ 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;
}

/**
* 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;
}

/**
* 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;
}

/**
* 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;
}

/**
* 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;
}

/**
* 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;
}

/**
* 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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/engine/Collision/Body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,24 @@ export class Body implements Clonable<Body> {

/**
* 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

Expand Down

0 comments on commit 85146de

Please sign in to comment.