pyaudiogame.App(title="Test app", fps=30)
The master/main class of the pyaudiogame engine.
- title is the name of your application's window.
- fps stands for frames per second and is how many times your game loop runs each second. The default is 30, but most graphical applications run at 60. Audio games do not use graphics, so don't really need the extra speed. Having the loop speed this low means that the app takes up much less memory.
pyaudiogame.App.__init__ | The initialization function of the pyaudiogame.App class |
pyaudiogame.App.logic | The method/function where all the game logic goes. |
pyaudiogame.App.set_defaults | A method that is run in init. This is to make a nice easy way of setting default settings when sub-classing |
pyaudiogame.App.run | Creates the screen and starts the game loop |
pyaudiogame.App.key_repeat | Toggles and sets what holding down a key does |
pyaudiogame.App.event_queue.schedule | Place all events that need a timer in this function |
The pyaudiogame.App class provides the core functionality needed to run an application. It captures keyboard input and schedules and runs events.
logic(actions) -> bool
The function you over-ride and fill with game logic.
Return a False when you wish the game loop to quit.
The actions is a dict of keyboard and mouse events as follows:
*['mousex'] The x coordinate of the mouse
*['mousey'] The y coordinate of the mouse
*['key'] The name of a key as a string. For example "space", "f", "return", "up"... To figure out what a key is, go to examples/keyboard_test.py
*['mouseClicked'] The state of the mouse click
*['mods'] a list of mod keys like ['ctrl', 'shift'] means that ctrl and shift are held down. ['shift'] means that just shift is held down
set_defaults
set_defaults(self)
-> None
Should really only be sub-classed to change the class variables. it is run when the class is initialized.
run() -> None
Creates the screen and starts the game loop. Call this at the bottom of your main script to start the app.
key_repeat
key_repeat(self, on=True, delay=1000, delay_before_first_repeat=1)
Toggles on and off what happens when a key is held down.
call with on=False to turn it off and
just put delay=200
to turn it back on.
delay_before_first_repeat
is the amount between the first event and the first of the repeating events. By default this is set to 1 millisecond as most people wish their repeating keyboard events to be steady. Passing 0 to this will toggle off the repeating.action_queue.schedule
schedule(function, delay=0, repeats=1, before_delay=False, *args, **kwargs)
Adds a function to the event queue to run delay seconds later.
hello_world()
but without the (). So like hello_world
. This function will run after or before the wait and will repeat the number of times specified.before_delay
if True will set the function to run before the timer runs. This is mostly used for repeating functions.*args **kwargs
If the function that is passed in takes arguments, they can be specified by either placing them after all the above arguments, or better, labeling them with keywords. So if our hello_world
function takes name as an argument, a schedule would look like: schedule(hello_world, 1, name="Joe")
hello_world
to run one time in one second and hello_world
will be passed the argument name.These are settings that can be changed or accessed by typing App.variable_name.
event_queue = ticker.Scheduler(time_format=0.001)
time_format
is how much to multiply the tick numbers by in order to make a second. Don't change this unless you know what you're doing.