Skip to content

Commit

Permalink
fix: Invalid color argument type when providing collider
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Feb 2, 2025
1 parent 19c076f commit 1cb7417
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions sandbox/tests/composite-collider/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Composite Collider</title>
</head>

<body>
<p>Composite Collider</p>
<script src="../../lib/excalibur.js"></script>
<script src="./index.js"></script>
</body>
</html>
64 changes: 64 additions & 0 deletions sandbox/tests/composite-collider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// <reference path='../../lib/excalibur.d.ts' />

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();
13 changes: 13 additions & 0 deletions src/engine/Actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
| {
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit 1cb7417

Please sign in to comment.