Now it's time to port game written in pygame framework to Android. If you want to know how to create games in pygame, see tutorial here Pygame tutorial 1.
If you already have working game for PC and want to port it, Pygame Subset for Android is the solution.
To port games written for PC to Andorid, we need to do simple modification in code to. Below are some of the guideline for porting
1. File name should be main.py
  Andorid run time need file should be named as main.py and runs main method in that file
2. Entry point for game function should be should be def main()
  Andorid run time need file should be named as main.py and runs main method in that file
3. Default font in Android is not supported, You have to use font file. Below are few font providers.
  http://www.dafont.com/sf-comic-script.font
  http://cooltext.com/Download-Font-Comics+Cartoon
4. import Andorid module to enable Andorid related functionality adding below lines to your code makes code run in both on PC and andorid device
try: import android except ImportError: android = None  We need to init() the andorid related functions
android.init()5. Life Cycle management
if android: if android.check_pause(): android.wait_for_resume()At any time, Android may ask your game pause to itself. This may occur when the user hits pause button, when the device goes to sleep, or when user switches to another application( like you get calls ). 6. Key Mapping    To operate game using PC instruction in pygame, We need to map pygame instruction to Android instruction. Below is the way to do it.
if android: android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)      Andorid keyCodes can be found here       Pygame keyCodes can be found here 7. Not every pygame module are supported in Android       List of supported pygame modules 8. Not every python modules are supported in Android       List of supported python modules 9. MOUSE BUTTON     As there is no mouse in andorid, no way to distinction between mouse button action. so event.button event is not supported. If you have below kind of code in your app, its time to remove it.
event.button == 1:10. android.keystore :     Its the certificate to install your app into Android device and to update your app in google play. In short dont loose it:D :D.       http://developer.android.com/tools/publishing/app-signing.html 11. Packaging:   Icon:   This is the image which you want to see as short cut when you install app in you Andorid device. File name: pygame-icon.png Presplash: This is the first image which is displayed while loading your game File name: pygame-presplash These are present in below folder .\templates 12. Debugging       In emulator You can follow the classic way of debugging by using print statements. Your print statement will be executed in android and will display on screen.
andorid.py logcat In andorid device I have tried app called Log Collector which captures andorid logs and send it to different devices. Log Collector 13: FPS: Frame Per Second is the rate at which you want to refresh/ draw your screen. You have to choose this as per your device. << ask Eric >> Option 1: Frame Per Second
# Event constant. TIMEREVENT = pygame.USEREVENT # The FPS the game runs at. FPS = 30 pygame.time.set_timer(TIMEREVENT, 1000 / FPS)Option 2:
self.clock = pygame.time.Clock() self.clock.tick(60)
python android.py installsdk3. After installation we need to configure Android-specific settings. run below command
python android.py configure mygameNote: mygame is the folder where your will keep your pygame code         Other configuration details are self explanatory 4. Use the android.py build command to build a the package on your device. run below command
python android.py build mygame release5. Use the android.py build command to install the package on your device. run below command
python android.py build mygame release installNote: To install you should have done SDK Manager.exe execution and         AVD Manager.exe should be running, check below information.
.\android-sdk\SDK Manager.exe and install the required things.Below is my Andorid SDK Manager configuration. Updating from command line
tools\android.bat update sdk --no-uiTip: use --help to see the various command-line options.
http://developer.android.com/sdk/AVD Manager.exe The AVD Manager provides a graphical user interface in which you can create and manage Android Virtual Devices (AVDs), which are required by the Android Emulator. To run
.\android-sdk\AVD Manager.exeBelow is my Andorid AVD Manager configuration. Click on start to launch the Emulator Go to home, we can see the app which is newly created here ( I am alread did release install )
Have you found any way to add ads to the app?
ReplyDelete