Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


little feedback with UI and callbacks


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Lysy   Members   -  Reputation: 657

Like
0Likes
Like

Posted 22 July 2014 - 02:01 PM

Hello there. So I'm playing aroung with python and pysfml, started writing pong clone. I began with creating UI, and I got little problem with callbacks and buttons. As you will see in the code (link below) in gamestatesettings.py I create a list of buttons, and in each of them I assign a callback method to invoke when pressed. And in this very method, I also invoke code on the same button explicitly e.g.

    def diff_up(self, engine):
        engine.game_settings.difficulty_up()
        self.butt_list[0].set_text('# ' + engine.game_settings.get_difficulty())

which i find inconvenient.

And I don't have any idea how could I do this look nice. So maybe someone here will be so kind and suggest some solution for me?

 

 

https://github.com/cosmonaut-paul/pysfml-pong



Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 17144

Like
5Likes
Like

Posted 22 July 2014 - 04:48 PM

One suggestion: instead of just passing the engine object to the callback, pass the engine object and the relevant control object.

So e.g.:

def diff_up(self, clickedButton, engine):
    engine.game_settings.difficulty_up()
    clickedButton.set_text('# ' + engine.game_settings.get_difficulty())


#3 Lysy   Members   -  Reputation: 657

Like
0Likes
Like

Posted 23 July 2014 - 11:13 AM

Well, yeah, that'll do the thing. Thanks.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS