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

UIButton onClick event not working #43

Closed
cbergen opened this issue Aug 28, 2018 · 2 comments
Closed

UIButton onClick event not working #43

cbergen opened this issue Aug 28, 2018 · 2 comments

Comments

@cbergen
Copy link

cbergen commented Aug 28, 2018

I'm trying to register a mouse click using the following:

const btn = UIButton.fromCircle( [p1, p2] );
btn.onClick( ui => {
    console.log('btn clicked');
});
btn.render( g => form.fillOnly("#000").circle( g ) );

The button renders but nothing appears in console when clicking.

@williamngan
Copy link
Owner

Hi @cbergen , you also need to put a UI.track in a player's "action" callback, so that the actual UI events are passed into UIButton. For example:

    action:( type, px, py) => {
      UI.track( arrayOfUIs, type, new Pt(px, py) );
    }

Take a look at line 85 in the UI demo here.

I do realize this might be a bit unintuitive, but this also makes the UI classes more flexible (eg, you can stop tracking anytime by not passing values to UI.track, or pass arbitrary values to it).

The API for UI classes will need some more thinking. If you have feedbacks after using it, please file issues. Thanks for trying it out!

@cbergen
Copy link
Author

cbergen commented Aug 30, 2018

That's a big help, thank you!

@cbergen cbergen closed this as completed Aug 30, 2018
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