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

Tapping anywhere on the screen triggers spriteSelected #79

Closed
Manguelo opened this issue Nov 18, 2020 · 3 comments
Closed

Tapping anywhere on the screen triggers spriteSelected #79

Manguelo opened this issue Nov 18, 2020 · 3 comments

Comments

@Manguelo
Copy link

Manguelo commented Nov 18, 2020

Not sure if this is intended functionality, but when I tap anywhere on the screen my interface components are set to their spriteSelected sprite.

Here is my game interface class:

class PlayerInterface extends GameInterface {
  @override
  void resize(Size size) {
    add(InterfaceComponent(
      sprite: Sprite('reset.png'),
      spriteSelected: Sprite('reset_selected.png'),
      height: 40,
      width: 100,
      id: 6,
      position: Position(150, 20),
      onTapComponent: () {
        gameRef.pause();
        showDialog(
          context: gameRef.context,
          builder: (context) {
            return WillPopScope(
              onWillPop: () {
                gameRef.resume();
                return Future.value(true);
              },
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(
                    width: 500,
                    height: 200,
                    child: Material(
                      borderRadius: BorderRadius.circular(10),
                      color: Colors.white,
                      child: Text('Wow a dialog!'),
                    ),
                  ),
                ],
              ),
            );
          },
        );
      },
    ));
    super.resize(size);
  }
}

I was able to resolve this issue by extending the InterfaceComponent class and modifying the following method:

  @override
  void onTapDown(int pointer, Offset position) {
    if (spriteSelected != null) spriteToRender = spriteSelected;
    super.onTapDown(pointer, position);
  }

to

  @override
  void onTapDown(int pointer, Offset position) {
    if (this.position.contains(position)) {
      spriteToRender = spriteSelected;
      super.onTapDown(pointer, position);
    }
  }
}

Here's a video of the issue I'm having:
ezgif com-video-to-gif

Take note of the reset button entering the selected state when moving the joystick. Let me know your thoughts; otherwise, plugin has been great so far! 🙌

If this is an issue, I wouldn't mind fixing and creating a PR

@RafaelBarbosatec
Copy link
Owner

Thank you very much for reporting this issue! I'll be uploading a version with this fix!

@Manguelo
Copy link
Author

That's great, thanks!

@RafaelBarbosatec
Copy link
Owner

Fix available in version 0.8.0! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants