📜 ⬆️ ⬇️

Introduction to Pygame Subset for Android

Good morning wish.

I want to share the results of my acquaintance with Python (which started 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 the search on Habré on the topic of the post did not give results, I would venture to suggest that the topic has not been raised before, but at the same time it will be of interest to people interested in using Python to develop applications that use media content, including Android.

So, Pygame Subset for Android (PS4A).
')
The Pygame Subset for Android is a subset of Pygame functionality to the Android platform. There is no need for any PC-like platforms to Android.

This is the text that the visitor encounters the main page of the PS4A site. There you can easily find links to download. Apk and install from the Android Market, as well as the table of contents of available documentation. Actually in the documentation you can find a list of modules that are ported (divided into groups in this way: android, android_mixer, pygame and Python) as well as guidelines for performing short-range actions. To be honest, the volume of documentation is not impressive, but for the beginning it is quite enough. In the same place, on the site, there is also an application template (with the encouraging name “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 increased possibilities in the direction of graphics. So I got PS4A. It was immediately decided to write a demo that would check the following functionality:
I admit that the resulting demo does not shine with functionality, but with the tasks set, in my opinion, it did it right. I also note that the development with the help of PS4A is almost the same as working with Pygame (unless it is sometimes necessary to check whether the modules you plan to use are supported), so the application behaves in exactly the same way on both Windows XP (Python 2.5.2) and LG Optimus One (PS4A 0.9.2), which is very convenient - it is not necessary 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 output primitives (lines and points). The rapid fall in FPS after drawing 100+ primitives has been noticed. In the lower left corner - toogle-button to enable / disable the delay for 50 milliseconds of each frame, and in the lower right corner - the button to clear the screen from the results of the creative process. The robot (the green character in the white square, in the screenshot it is in the lower right corner hiding behind the wide screen-cleaning button behind a broad back) moves around the screen depending on the data read from the accelerometer. On the device, the application works correctly, but the FPS modestly keeps around 20-25.

As a conclusion, it can be said that PS4A can hardly be used to develop any serious games or media applications (the speed leaves much to be desired, and I don’t even have OpenGL support in the plans), but for small sprite demos - quite.

Applications:


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

(To install the application on the device, simply unpack it from the archive and upload it to / 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

Source: https://habr.com/ru/post/119831/


All Articles