diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ee33a342..45246a6c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Fixed issue where the ActorArgs type hint would not error when providing a color causing confusion when it didn't produce a default graphic. - Fixed false positive warning when adding timers - Fixed issue where gamepad buttons wouldn't progress the default loader play button - Add defense around middling Safari fullscreen support and update documentation diff --git a/sandbox/tests/composite-collider/index.html b/sandbox/tests/composite-collider/index.html new file mode 100644 index 000000000..30b925d2f --- /dev/null +++ b/sandbox/tests/composite-collider/index.html @@ -0,0 +1,15 @@ + + + + + + + Composite Collider + + + +

Composite Collider

+ + + + diff --git a/sandbox/tests/composite-collider/index.ts b/sandbox/tests/composite-collider/index.ts new file mode 100644 index 000000000..3b5787530 --- /dev/null +++ b/sandbox/tests/composite-collider/index.ts @@ -0,0 +1,64 @@ +/// + +var game = new ex.Engine({ + width: 1000, + height: 1000, + physics: { + solver: ex.SolverStrategy.Arcade + } +}); + +game.toggleDebug(); + +let roomShape = new ex.Rectangle({ width: 700, height: 500, color: ex.Color.DarkGray, strokeColor: ex.Color.White }); + +var topEdgeCollider = ex.Shape.Box(700, 10, ex.Vector.Zero, ex.vec(0, 0)); +var leftEdgeCollider = ex.Shape.Box(10, 500, ex.Vector.Zero, ex.vec(0, 0)); +var rightEdgeCollider = ex.Shape.Box(10, 500, ex.Vector.One, ex.vec(700, 500)); +var bottomEdgeCollider = ex.Shape.Box(700, 10, ex.Vector.One, ex.vec(700, 500)); +var compositeCollider = new ex.CompositeCollider([topEdgeCollider, leftEdgeCollider, rightEdgeCollider, bottomEdgeCollider]); + +class RoomActor extends ex.Actor { + roomId: string; + constructor() { + super({ + pos: new ex.Vector(0, 0), + collider: compositeCollider, + collisionType: ex.CollisionType.Fixed + }); + this.graphics.anchor = ex.vec(0, 0); + this.graphics.use(roomShape); + } +} +game.add(new RoomActor()); + +var player = new ex.Actor({ + pos: ex.vec(100, 270), + width: 16, + height: 16, + color: ex.Color.Blue, + collisionType: ex.CollisionType.Active +}); + +player.onPostUpdate = () => { + const speed = 164; + player.vel = ex.vec(0, 0); + if (game.input.keyboard.isHeld(ex.Keys.Right)) { + player.vel.x = speed; + } + if (game.input.keyboard.isHeld(ex.Keys.Left)) { + player.vel.x = -speed; + } + if (game.input.keyboard.isHeld(ex.Keys.Up)) { + player.vel.y = -speed; + } + if (game.input.keyboard.isHeld(ex.Keys.Down)) { + player.vel.y = speed; + } +}; +game.add(player); + +game.currentScene.camera.strategy.elasticToActor(player, 0.8, 0.9); +game.currentScene.camera.zoom = 2; + +game.start(); diff --git a/src/engine/Actor.ts b/src/engine/Actor.ts index 81e54b9ca..73fe61521 100644 --- a/src/engine/Actor.ts +++ b/src/engine/Actor.ts @@ -145,12 +145,15 @@ type ColliderArgs = { /** * Optionally supply a collider for an actor, if supplied ignores any supplied width/height + * + * No default graphigc is created in this case */ collider?: Collider; width?: undefined; height?: undefined; radius?: undefined; + color?: undefined; } // box collider | { @@ -163,6 +166,11 @@ type ColliderArgs = */ height?: number; + /** + * Optionally set the color of a rectangle graphic for the actor + */ + color?: Color; + collider?: undefined; radius?: undefined; } @@ -173,6 +181,11 @@ type ColliderArgs = */ radius?: number; + /** + * Optionally set the color on a circle graphic for the actor + */ + color?: Color; + collider?: undefined; width?: undefined; height?: undefined;