Pygame on Android

I was wondering if someone could give me a detailed explanation on how to run a game/app developed using Pygame on an Android phone. I recently finished programming PacMan and it works perfectly on my computer, but I think it would be awesome if I could get it running on my phone. I tried following the instructions at http://pygame.renpy.org/android-packaging.html , but every time i run "import android" on the IDLE I get an error saying it did not find the module. Could someone clearly explain how to set up the android module?

Also, in my program I used code such as if (event.key == K_UP or event.key == K_w): direction = UP. However there are no arrow keys on a phone. What code would I need to use to see if the user swiped the screen with their fingers from up -> down or left -> right, etc.

Any help would be great. Thanks <3


There is a pyGame subset for android. However this requires special reworking and changing the program. Hopefully it will not be to hard.

http://pygame.renpy.org/writing.html

http://pygame.renpy.org/index.html

However about your second question i am unable to awnser because I am Not yet experienced enough.


我认为Android的pygame子集是好的,但我不相信它的功能,我使用kivy作为其跨平台,如果你决定使用android的pygame子集你的Android设备的屏幕上的翻转触摸将是你的鼠标在桌面上的运动,所以我马说对待触摸作为老鼠好运


There are some pretty good answers for your first part already so I won't answer that. (I came here looking into what to use for it too!)

However the second part of your question should be a lot easier.

Have a mouse object that on a mouse down event will save the coordinates of the touch to an MX and MY variable Then when the mouse up event is triggered takes the new coordinates and calculates a vector using the MX and MY and this new point ie. The distance and angle of the swipe. Use trigonometry or the math module for the angle (research arctan2).

You can then use this in an if, elif, else to determine what quadrant the angle was and the distance to determine whether the swipe was valid if it's greater than a certain value.

I'm on mobile so unfortunately I can't give an example, however I'm certain you're apt to work out the solution with this guidance.

链接地址: http://www.djcxy.com/p/91194.html

上一篇: '开关'比'如果'更快?

下一篇: Android上的Pygame