Python Forum
[PyGame] Best way to pass data to the few game states with the same superclass?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Best way to pass data to the few game states with the same superclass?
#4
Doesn't make it wrong. Just make program less flexible. Frame rate shouldn't be a global or a constant. I Would just wrap it as Setting class. Then make variable in share data class. Then you can just pass one class to handle all data. Good thing about classes. They are reference. So passing is low memory and fast.

class Setting:
    def __init__(self):
        self.end_time = 180
Then I put it in my game manger.
class GameManager:
    def __init__(self, *args, **kwargs):
        self.setting = Setting()
        self.game_data = GameData()
        self.gfx = self.game_data.textures
Then I would pass manager to scene/state. This way every state that inherit will already have access to data.
class Scene:
    def __init__(self, manager):
        self.manager = manager
        self.gfx = manager.gfx
Hope this help you to find your style.
Anyone can program. Only a few can program well.
Milosz likes this post
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
RE: Best way to pass data to the few game states with the same superclass? - by Windspar - Oct-17-2021, 01:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Variables shared between game states, how to? michael1789 5 3,575 Dec-10-2019, 10:09 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020