diff --git a/CHANGELOG.md b/CHANGELOG.md index c20b0997..1d7b778e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ are returned ### Fixed +- Fixed issue where `ex.ScreenElement` pointer events were not working by default. - Fixed issue where setting lineWidth on `ex.Circle` was not accounted for in the bitmap - Fixed issue in macos where the meta key would prevent keyup's from firing correctly - Fixed issue when excalibur was hosted in a x-origin iframe, the engine will grab window focus by default if in an iframe. This can be suppressed with `new ex.Engine({grabWindowFocus: false})` diff --git a/sandbox/index.html b/sandbox/index.html index 2211e85c..af2e0dc0 100644 --- a/sandbox/index.html +++ b/sandbox/index.html @@ -11,6 +11,7 @@
  • Sandbox Platformer
  • Multi-engine
  • Sprite Tint
  • +
  • ScreenElement Pointer by default
  • Clone Behavior
  • Parallel Actions
  • Isometric Map
  • diff --git a/sandbox/tests/screenelementpointer/index.html b/sandbox/tests/screenelementpointer/index.html new file mode 100644 index 00000000..c454b9fe --- /dev/null +++ b/sandbox/tests/screenelementpointer/index.html @@ -0,0 +1,13 @@ + + + + + + Pointer on Screen Element + + +

    Click the ScreenElement an alert should fire

    + + + + \ No newline at end of file diff --git a/sandbox/tests/screenelementpointer/index.ts b/sandbox/tests/screenelementpointer/index.ts new file mode 100644 index 00000000..d64a5ba0 --- /dev/null +++ b/sandbox/tests/screenelementpointer/index.ts @@ -0,0 +1,29 @@ + +class StartButton extends ex.ScreenElement { + constructor(x: number, y: number) { + super({ + x, y + }) + } + onInitialize() { + this.graphics.use(new ex.Rectangle({ + color: ex.Color.Green, + width: 300, + height: 50 + })); + // ... + this.on('pointerup', () => { + alert("I've been clicked"); + }) + // ... + } +} + +var engine = new ex.Engine({ + width: 800, + height: 400 +}); + +engine.add(new StartButton(400, 200)); + +engine.start(); \ No newline at end of file diff --git a/src/engine/ScreenElement.ts b/src/engine/ScreenElement.ts index 4177cad2..0f3fd145 100644 --- a/src/engine/ScreenElement.ts +++ b/src/engine/ScreenElement.ts @@ -27,6 +27,8 @@ export class ScreenElement extends Actor { this.get(TransformComponent).coordPlane = CoordPlane.Screen; this.anchor = config?.anchor ?? vec(0, 0); this.body.collisionType = config?.collisionType ?? CollisionType.PreventCollision; + this.pointer.useGraphicsBounds = true; + this.pointer.useColliderShape = false; if (!config?.collider && config?.width > 0 && config?.height > 0) {