Introducing Pygame Subset for Android

I wish you good health.

I want to share the results of my acquaintance with Python (which began not so long ago), and in particular with the port on the Android platform of the rather well-known Pygame media library (which, in turn, is a wrapper for the equally well-known SDL). Since a search on the hub for the topic of the post did not return results, I’m risking to assume that the topic has not been raised before, but at the same time it will be interesting to people interested in using Python to develop applications that use media content, including for Android.

So, Pygame Subset for Android (PS4A).

The Pygame Subset for Android is a port of a subset of Pygame functionality to the Android platform. The goal of the project is to allow the creation of Android-specific games, and to ease the porting of games from PC-like platforms to Android.

It is with this text that the main page of the PS4A website meets the visitor. There you can easily find links for downloading .apk and installation from the Android Market, as well as a table of contents of existing documentation. Actually in the documentation you can find a list of modules that are ported (divided into groups this way: android, android_mixer, pygame and Python) as well as manuals for performing specific actions. To be honest, the amount of documentation is not impressive, but for a start it’s enough. There, on the site, there is an application template (with the encouraging title “Writing a game”, but very simplified - the finished application can be downloaded from the link below), and links to parent technologies / libraries (Pygame, SDL, Python, Jtar).

For the first time, I tried scripting for Android thanks to Scripting Layer for Android and was intrigued by the expansion of capabilities in the direction of graphics. So I came across PS4A. Immediately, it was decided to write a demo that would check the following functionality:
  • Reading accelerometer data
  • Output graphic primitives, sprites
  • Text output
  • Performance test (in other words, FPS output)
  • Touch Screen Input
I admit that the resulting demo does not shine with functionality, but, in my opinion, it completely coped with the tasks. I also note that development using PS4A is practically no different from working with Pygame (unless you sometimes need to check whether the modules that you plan to use are supported), so the application behaves exactly the same on both Windows XP (Python 2.5.2) and LG Optimus One (PS4A 0.9.2), which is very convenient - you do not need to check every edit on the device.

Here's what happened:
image

In the upper left corner are displayed: FPS, the last processed event, data read from the accelerometer and the total number of displayed primitives (lines and points). FPS drops rapidly after rendering 100+ primitives. In the lower left corner is the toogle-button to enable / disable a delay of 50 milliseconds of each frame, and in the lower right corner there is a button to clear the screen from the results of the creative process. A robot (a green character in a white square, in the screenshot it is in the lower right corner, hiding half of the screen clear button behind a wide back) moves around the screen depending on the data read from the accelerometer. On the device, the application works correctly, but FPS modestly keeps in the region of 20-25.

As a conclusion, we can hardly say that PS4A can be used to develop any serious games or media applications (performance leaves much to be desired, and OpenGL support, as I understand it, is not even in the plans), but for small sprite demos it’s quite.

Applications:


  1. Demo from “Writing a game” (changes the color of the screen when pressed)
  2. My demo (warning for aesthetes and gurus - the code is rather bulky and does not pretend to an elegant solution to the problem)

(To install on the device, it is enough to unpack the application from the archive and fill it in / sdcard / pygame / <separate_folder>, after which it can be found in the PS4A main menu).

References:


  1. Pygame Subset for Android - pygame.renpy.org
  2. Pygame - pygame.org/news.html
  3. Blog on the book “Invent Your Own Computer Games with Python”, there is also a link to a free eBook - inventwithpython.com/blog/category/code-comments

Also popular now: