Gamestate management

40 views
Skip to first unread message

Andreas Grätz

unread,
May 7, 2012, 12:22:28 PM5/7/12
to pyglet...@googlegroups.com
Hello,

has anyone an example for gamestate management for pyglet. In C++ I use a singleton, is there something similar here?

Best regards

Andreas

alex23

unread,
May 9, 2012, 8:33:29 PM5/9/12
to pyglet-users
On May 8, 2:22 am, Andreas Grätz <andreas...@googlemail.com> wrote:
> has anyone an example for gamestate management for pyglet. In C++ I use a
> singleton, is there something similar here?

Modules are effectively singletons in Python. Here's a rough example:

gamestate.py:
# empty module

a.py:
import gamestate
gamestate.loaded_a = True
gamestate.foo = 'bar'

b.py:
import gamestate
gamestate.loaded_b = True
gamestate.foo = 'BAZ'

main.py:
import a
import b
import gamestate
print 'Loaded A? %s Loaded B? %s' % (gamestate.loaded_a,
gamestate.loaded_b)
print 'gamestate.foo = %s' % gamestate.foo
Reply all
Reply to author
Forward
0 new messages