Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScreenElement sample code needs pointer.useGraphicsBounds = true #2668

Closed
max-vogler opened this issue Jun 26, 2023 · 2 comments · Fixed by #2669
Closed

ScreenElement sample code needs pointer.useGraphicsBounds = true #2668

max-vogler opened this issue Jun 26, 2023 · 2 comments · Fixed by #2669
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior

Comments

@max-vogler
Copy link

Steps to Reproduce

Implement the sample screen element with pointerup listener code from the docs.

class StartButton extends ex.ScreenElement {
   // ...
  onInitialize() {
    this.graphics.add('idle', Resources.StartButtonBackground)
    // ...
    this.on('pointerup', () => {
      alert("I've been clicked")
    })
    // ...
  }
}

Expected Result

An alert should popup on click, especially since the docs state "They automatically capture pointer events".

Actual Result

Nothing happens, since useGraphicsBounds is false since v0.25.2.

Pointers can now be configured to use the collider or the graphics bounds as the target for pointers with the ex.PointerComponent

useColliderShape - (default true) uses the collider component geometry for pointer events
useGraphicsBounds - (default false) uses the graphics bounds for pointer events

Environment

  • browsers and versions: Chrome 114
  • operating system: macOS 13.2
  • Excalibur versions: 0.27.0, likely since 0.25.2

Current Workaround

class StartButton extends ScreenElement {
  constructor(config?: ActorArgs) {
    super(config);
    this.pointer.useGraphicsBounds = true;
    this.pointer.useColliderShape = false;
  }
@eonarheim
Copy link
Member

@max-vogler Thanks for the issue! Appreciate the workaround you found!

Definitely unexpected, we'll get that fixed asap.

@eonarheim eonarheim added the bug This issue describes undesirable, incorrect, or unexpected behavior label Jun 27, 2023
eonarheim added a commit that referenced this issue Jun 27, 2023
Closes #2668

Update `ex.ScreenElement` to set a sensible default in it's constructor so it uses graphics bounds to capture pointers
@max-vogler
Copy link
Author

Thanks for the fast and comprehensive fix, @eonarheim!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants