Skip to content

Commit

Permalink
fix: [#2668] ScreenElement pointer capture configured properly
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Jun 27, 2023
1 parent 214e609 commit c08feeb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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})`
Expand Down
1 change: 1 addition & 0 deletions sandbox/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<li><a href="html/index.html">Sandbox Platformer</a></li>
<li><a href="tests/multi-engine/">Multi-engine</a></li>
<li><a href="tests/sprite-tint/">Sprite Tint</a></li>
<li><a href="tests/screenelementpointer/">ScreenElement Pointer by default</a></li>
<li><a href="tests/clonebehavior/">Clone Behavior</a></li>
<li><a href="tests/parallel/">Parallel Actions</a></li>
<li><a href="tests/isometric/">Isometric Map</a></li>
Expand Down
13 changes: 13 additions & 0 deletions sandbox/tests/screenelementpointer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pointer on Screen Element</title>
</head>
<body>
<p>Click the ScreenElement an alert should fire</p>
<script src="../../lib/excalibur.js"></script>
<script src="./index.js"></script>
</body>
</html>
29 changes: 29 additions & 0 deletions sandbox/tests/screenelementpointer/index.ts
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 2 additions & 0 deletions src/engine/ScreenElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c08feeb

Please sign in to comment.