Difference between revisions of "Development Team/Sugargame"

From Sugar Labs
Jump to navigation Jump to search
Line 32: Line 32:
 
== Using Sugargame ==
 
== Using Sugargame ==
 
   
 
   
To use Sugargame in an activity, copy the sugargame folder into the activity's
+
=== Porting a Pygame program ===
source directory.
+
 
+
To use Sugargame to Sugarize a Pygame program, set up an activity directory and copy the Sugargame package to it.
 +
 
 
The activity directory should look something like this:
 
The activity directory should look something like this:
 
   
 
   
Line 42: Line 43:
 
   mygame.py            - Pygame code
 
   mygame.py            - Pygame code
 
   setup.py            - Install script
 
   setup.py            - Install script
 
+
 
To make the Activity class, start with test/TestActivity.py.   
+
To make the Activity class, start with test/TestActivity.py from the Sugargame distribution. 
 +
 
 +
The activity should create a single PygameCanvas widget and call run_pygame on it.
 +
 
 +
self._canvas = sugargame.canvas.PygameCanvas(self)
 +
self.set_canvas(self._canvas)
 +
       
 +
# Start the game running.
 +
  self._canvas.run_pygame(self.game.run)
 +
 
 +
In your Pygame main loop, pump the GTK message loop:
 +
 
 +
  while gtk.events_pending():
 +
      gtk.main_iteration()
 +
 
 +
=== Adding Pygame to an activity ===
 +
 
 +
TODO
  
 
== Support ==
 
== Support ==

Revision as of 10:53, 21 November 2009

Sugargame

Sugargame is a Python package which allows Pygame programs to run well under Sugar. It is fork of the olcpgames framework, which is no longer maintained.

Sugargame embeds the Pygame window into a GTK window, and translates GTK events to Pygame events.

What it does:

  • Wraps a Sugar activity around an existing Pygame program with few changes
  • Allows Sugar toolbars and other widgets to be added to the activity UI
  • Provides hooks for saving to and restoring from the Journal

Differences between Sugargame and olpcgames

The olpcgames framework provides a wrapper around Pygame which attempts to allow a Pygame program to run mostly unmodified under Sugar. To this end, the Pygame program is run in a separate thread with its own Pygame message loop while the main thread runs the GTK message loop. Also, olpcgames wraps Sugar APIs such as the journal and mesh into a Pygame-like API.

Sugargame takes a simpler approach; it simply offers a way to embed Pygame into a GTK widget. The Sugar APIs are used to interact with Sugar, the Pygame APIs are used for the game.

Sugargame advantages:

  • Simpler code
  • More elegant interface between Pygame and GTK
  • Runs as a single thread: no thread related segfaults
  • Possible to use Sugar widgets with Pygame

Sugargame limitations:

  • No support for Pango or SVG sprites (yet)

Using Sugargame

Porting a Pygame program

To use Sugargame to Sugarize a Pygame program, set up an activity directory and copy the Sugargame package to it.

The activity directory should look something like this:

  activity/            - Activity directory: activity.info, SVG icon, etc.
  sugargame/           - Sugargame package
  MyActivity.py        - Activity class
  mygame.py            - Pygame code
  setup.py             - Install script

To make the Activity class, start with test/TestActivity.py from the Sugargame distribution.

The activity should create a single PygameCanvas widget and call run_pygame on it.

self._canvas = sugargame.canvas.PygameCanvas(self)
self.set_canvas(self._canvas)
       
# Start the game running.
self._canvas.run_pygame(self.game.run)

In your Pygame main loop, pump the GTK message loop:

  while gtk.events_pending():
      gtk.main_iteration()

Adding Pygame to an activity

TODO

Support

For help with Sugargame, please email the Sugar Labs development list:

sugar-devel@lists.sugarlabs.org

Author

Sugargame is developed by Wade Brainerd <wadetb@gmail.com>.

It is loosely based on the source code to the olpcgames framework, developed by the One Laptop Per Child project.