Problem of integration of pgu (http://code.google.com/p/pgu/) module to pyGame (http://www.pygame.org/).
On your game « PyOrg », you use the pgu (http://code.google.com/p/pgu/) module for the graphical user interface. I would like to do the same thing for my own game (https://github.com/Nekrofage/KomandoPython). But I have a problem to integrate the gui to the pygame. To explain my problem, I have this archive : http://nekrocite.info/python/pgu.zip
where there are the move_sprite_keyboard_smooth.py example file and the same file : sprite_smooth.py with the pgu.
When I move the sprite the movement is very strange, the movement is not fluid
For the first example, if I press down the right key all the time the sprite movement if okay. But for the second example, the sprite movement become more and more quickly
Answer from Marcus Møller creator of pyORPG (http://www.powrtoch.org/pyorpg/) :
A little trial and error shows that this behaviour is caused by app.init(c) on line 102-103.
When looking through the source of PGU, you’ll find the app.init() function in file pgu/gui/app.py. In the app.init() function you’ll see that this pygame function is being called:
line 104: pygame.key.set_repeat(500,30)
This tells pygame to repeat event keys 30 times with a delay of 500 ms.
So that leaves you with two options for fixing your problem:
(Worst option) You can comment out line 104 in pgu/gui/app.py so that the pygame.key.set_repeat() function isn’t called on app.init(), or
(Best option) set a limit for the player velocity.
The best gamedesign-wise option is to limit the velocity of the player. This is easily done by adding the following lines to the top of your player.update() function:
if self.change_x > 3: self.change_x = 3
elif self.change_x < -3: self.change_x = -3 if self.change_y > 3: self.change_y = 3
elif self.change_y < -3: self.change_y = -3 These few lines limit the velocity of your player. If you comment out line 104 in pgu/gui/app.py, you'll risk breaking PGU. PGU won't be able to have key repeats in text boxes etc., requiring users to re-press the "d" buttons if they were to enter "ddddddddddddddd" in a textbox.