Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

little feedback with UI and callbacks

4: Adsense

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   

685
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



#2 ApochPiQ   Moderators   

22551
Like
5Likes
Like

Posted 22 July 2014 - 04:48 PM

*
POPULAR

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())

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

#3 Lysy   Members   

685
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.