diff --git a/CHANGELOG.md b/CHANGELOG.md
index e0b30f72..9004b863 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -46,6 +46,7 @@ are returned
### Fixed
+- Fixed issue where the `ex.ScreenElement` anchor was not being accounted for properly when passed as a constructor parameter.
- Fixed issue where you could not use multiple instances of Excalibur on the same page, you can now have as many Excalibur's as you want (up to the webgl context limit).
- Fixed issue where `ex.ScreenElement` would log a warning when created without a height or width
- Fixed issue where `ex.Sound` would get confused parsing and playing sound files with a querystring in their path
diff --git a/sandbox/tests/screenelement/index.html b/sandbox/tests/screenelement/index.html
new file mode 100644
index 00000000..b58b83c5
--- /dev/null
+++ b/sandbox/tests/screenelement/index.html
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+ Screen Element
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sandbox/tests/screenelement/index.ts b/sandbox/tests/screenelement/index.ts
new file mode 100644
index 00000000..a9840262
--- /dev/null
+++ b/sandbox/tests/screenelement/index.ts
@@ -0,0 +1,29 @@
+
+var engine = new ex.Engine({
+ width: 600,
+ height: 400
+});
+
+engine.debug.entity.showId = false;
+engine.debug.collider.showGeometry = true;
+engine.debug.transform.showPosition = true;
+
+engine.showDebug(true);
+
+var image = new ex.ImageSource('./spritefont.png');
+
+var loader = new ex.Loader([image]);
+
+var screenElement = new ex.ScreenElement({
+ pos: ex.vec(engine.screen.halfDrawWidth, engine.screen.halfDrawHeight),
+ width: 100,
+ height: 100,
+ anchor: ex.Vector.Half
+});
+// screenElement.collider.useBoxCollider(100, 100, ex.Vector.Half);
+
+screenElement.graphics.use(image.toSprite(), { anchor: ex.vec(0.5, 0.5) });
+
+engine.currentScene.add(screenElement);
+
+engine.start(loader);
\ No newline at end of file
diff --git a/sandbox/tests/screenelement/spritefont.png b/sandbox/tests/screenelement/spritefont.png
new file mode 100644
index 0000000000000000000000000000000000000000..a7fbf645bcf9e05dbcaf779bdf0610385cb06295
GIT binary patch
literal 1357
zcmeAS@N?(olHy`uVB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+xR-~ZTdrje~bZP;LzTEL*VVXIo~{=
z@6GS{er)&W&+E=T%f0{iUo<@7;s~VKHGhBcF6!wzpqtcV&A`CG;OXk;vd$@?2>?1-
B!W94j
literal 0
HcmV?d00001
diff --git a/src/engine/ScreenElement.ts b/src/engine/ScreenElement.ts
index 9664b24b..4177cad2 100644
--- a/src/engine/ScreenElement.ts
+++ b/src/engine/ScreenElement.ts
@@ -25,9 +25,11 @@ export class ScreenElement extends Actor {
constructor(config?: ActorArgs) {
super({ ...config });
this.get(TransformComponent).coordPlane = CoordPlane.Screen;
- this.anchor = vec(0, 0);
- this.body.collisionType = CollisionType.PreventCollision;
- if (config?.width > 0 && config?.height > 0) {
+ this.anchor = config?.anchor ?? vec(0, 0);
+ this.body.collisionType = config?.collisionType ?? CollisionType.PreventCollision;
+ if (!config?.collider &&
+ config?.width > 0 &&
+ config?.height > 0) {
this.collider.useBoxCollider(this.width, this.height, this.anchor);
}
}
diff --git a/src/spec/ScreenElementSpec.ts b/src/spec/ScreenElementSpec.ts
index 8f8d7f76..f79621e2 100644
--- a/src/spec/ScreenElementSpec.ts
+++ b/src/spec/ScreenElementSpec.ts
@@ -48,6 +48,44 @@ describe('A ScreenElement', () => {
expect(logger.warn).not.toHaveBeenCalled();
});
+ it('can be constructed with a non-default anchor', () => {
+
+ const sut = new ScreenElement({
+ width: 100,
+ height: 100,
+ anchor: ex.vec(.5, .5)
+ });
+
+ expect(sut.anchor).toBeVector(ex.vec(.5, .5));
+ expect(sut.collider.get()).toBeInstanceOf(ex.PolygonCollider);
+ expect(sut.collider.get().bounds.width).toBe(100);
+ expect(sut.collider.get().bounds.height).toBe(100);
+ expect(sut.collider.get().bounds.left).toBe(-50);
+ expect(sut.collider.get().bounds.right).toBe(50);
+ expect(sut.collider.get().bounds.top).toBe(-50);
+ expect(sut.collider.get().bounds.bottom).toBe(50);
+ });
+
+ it('can be constructed with a non-default collider', () => {
+
+ const sut = new ScreenElement({
+ width: 100,
+ height: 100,
+ collisionType: ex.CollisionType.Active,
+ collider: ex.Shape.Circle(50)
+ });
+
+ expect(sut.anchor).toBeVector(ex.vec(0, 0));
+ expect(sut.body.collisionType).toBe(ex.CollisionType.Active);
+ expect(sut.collider.get()).toBeInstanceOf(ex.CircleCollider);
+ expect(sut.collider.get().bounds.width).toBe(100);
+ expect(sut.collider.get().bounds.height).toBe(100);
+ expect(sut.collider.get().bounds.left).toBe(-50);
+ expect(sut.collider.get().bounds.right).toBe(50);
+ expect(sut.collider.get().bounds.top).toBe(-50);
+ expect(sut.collider.get().bounds.bottom).toBe(50);
+ });
+
it('is drawn when visible', () => {
screenElement.graphics.visible = true;
screenElement.graphics.onPostDraw = jasmine.createSpy('draw');