pygamepal package

pygamepal.button

class pygamepal.button.Button(input, position=(0, 0), size=(100, 50), label=None, fgColor='white', bgColor='black', borderWidth=1, borderColor='white', image=None, onHighlighted=None, onSelected=None, updateMethod=None, drawMethod=None, keyCode=None)

Bases: object

draw(surface)
drawBackground(screen)
drawBorder(screen)
drawImage(screen)
drawText(screen)
property isHighlighted
property isSelected
setHighlighted()
setSelected()
update()

pygamepal.camera

class pygamepal.camera.Camera(position=(0, 0), size=(640, 480), target=(0, 0), lazyFollow=0, zoom=1, minZoom=0.1, maxZoom=10, lazyZoom=0, backgroundColor='cornflowerblue', borderColor='black', borderThickness=2, clamp=False, clampRect=(0, 0, 1000, 1000), oscillateSpeed=0.2, shakeMagnitude=30, shakeDirection=(1, 0), shakeDampening=0.4, shakeNoise=0.8)

Bases: object

A camera can be used to render any source surface to another destination surface, using its parameters (size, position, target position, zoom, etc.). Example code.

https://github.com/rik-cross/pygamepal/blob/main/examples/gifs/cameraExample.gif?raw=true
Parameters:
  • position (tuple(int, int)) – the top-left (x, y) coordinate for the camera.

  • size (tuple(int, int)) – the size (w, h) of the camera (default = (640, 480), or the parent Scene size if used within a Scene).

  • target (tuple(int, int)) – the coordinate (x, y) of the source surface to draw at the center of the camera (default = (0, 0)).

  • lazyFollow (float) – the delay when updating the camera target. 0 = instant snap to target, 1 = no movement (default = 0).

  • zoom (float) – the amount to scale the source target (default = 1).

  • minZoom (float) – the minimum allowed zoom (default = 0.1).

  • maxZoom (float) – the maximum allowed zoom (default = 10).

  • lazyZoom (float) – the delay when updating the zoom calue. 0 = instant zoom, 1 = no change in zoom (default = 0).

  • backgroundColor (pygame.Color) – the background color (default = ‘cornflowerblue’).

  • borderColor (pygame.Color) – the color of the border (default = ‘black’).

  • borderThickness (int) – the thickness of the border(default = 2).

  • clamp (bool) – specifies whether the camera should stay within a specific boundary of the source surface (default = False).

  • clampRect (tuple(int, int, int, int)) – the boundary (x, y, w, h) of the source surface that the camera should stay within.

  • oscillateSpeed (float) – the speed at which the camera should shake (default = 0.2).

  • shakeMagnitude (int) – the magnitude of the camera shake (default = 30).

  • shakeDirection (tuple(float, float)) – the (x, y) direction of the shake (default = (1, 0)).

  • shakeDampening (float) – the reduction in camera shake magnitude each frame (default = 0.4).

  • shakeNoise (float) – the amount of random noise to add to the shake (default = 0.8).

draw(surface, destSurface)

Draws the source surface to the destination surface, using the camera parameters. This method must be called each frame if using a camera in isolation, but the method is called automatically for cameras with a parent scene.

Parameters:
  • surface (pygame.Surface) – the surface to draw.

  • destSurface (pygame.Surface) – the surface to draw to.

property lazyFollow

Get / set the lazy follow value, between 0 and 1.

property lazyZoom

Get / set the lazy zoom value, between 0 and 1.

setTarget(value, instant=False)

Set the camera target position. This method permits the instant setting of a position.

Parameters:

instant (bool) – set the position instantly, ignoring the stored ‘lazyFollow’ value (default = False).

setZoom(value, instant=False)

Set the camera target zoom value. This method permits the instant setting of the zoom.

Parameters:

instant (bool) – set the zoom value instantly, ignoring the stored ‘lazyZoom’ value (default = False).

shake(direction=None)

Start a camera shake.

Parameters:

direction (tuple(float, float)) – the (x, y) direction of the shake (default = None, use the stored direction).

update(deltaTime=1)

Updates the camera target position and, zoom and shake. This method must be called each frame if using a camera in isolation, but the method is called automatically for cameras with a parent scene.

Parameters:

deltaTime (float) – the game time elapsed since the last frame (default = 1).

property zoom

Get / set the zoom value (between specified ‘minZoom’ and ‘maxZoom’ values).

pygamepal.collider

class pygamepal.collider.Collider(position=(0, 0), size=(0, 0), offset=(0, 0), drawColor='red')

Bases: object

draw(surface)
property h
update()
property w
property x
property y

pygamepal.drawText

pygamepal.drawText.drawText(surface, text, position=[0, 0], font=None, antialias=True, color='white', backgroundColor=None, centerX=False, centerY=False)

pygamepal.flatten

pygamepal.flatten.flatten(list)

pygamepal.game

class pygamepal.game.Game(size=(640, 480), caption='', fps=60, fullscreen=False)

Bases: object

addButton(button)
addCollider(collider)
addSprite(sprite)
addTrigger(trigger)
draw()
property icon
init()
quit()
removeButton(button)
removeCollider(collider)
removeSprite(sprite)
removeTrigger(trigger)
run()
update()

pygamepal.input

class pygamepal.input.Input(longPressDuration=60, doublePressTimeout=30)

Bases: object

getKeyDownDuration(keyCode)
getKeyLongPressPercentage(keyCode)
getMouseButtonDownDuration(mouseButton)
getMouseButtonLongPressPercentage(mouseButton)
getMouseCursorPosition()
getMouseDirection()
isKeyDoublePressed(keyCode)
isKeyDown(keyCode)
isKeyLongDown(keyCode)
isKeyLongPressed(keyCode)
isKeyPressed(keyCode)
isKeyReleased(keyCode)
isMouseButtonDoublePressed(mouseButton)
isMouseButtonDown(mouseButton)
isMouseButtonLongDown(mouseButton)
isMouseButtonLongPressed(mouseButton)
isMouseButtonPressed(mouseButton)
isMouseButtonReleased(mouseButton)
update(deltaTime=1)

pygamepal.particles

class pygamepal.particles.Particle(position, velocity, acceleration, lifetime, size, sizeDecay, color)

Bases: object

draw(surface)
update(deltaTime=1)
class pygamepal.particles.Particles(emitterPosition=(0, 0), emitterSize=(0, 0), emitterLifetime=100, emitterVelocity=(0, 0), emitterAcceleration=(0, 0), emitterParticleDelay=5, particleVelocityMin=(-1, -1), particleVelocityMax=(1, 1), particleAccelerationMin=(0, 0), particleAccelerationMax=(0, 0), particleLifetime=100, particleSize=20, particleSizeDecay=0.2, particleColors=None)

Bases: object

draw(surface)
update(deltaTime=1)

pygamepal.scene

class pygamepal.scene.Scene(game, worldSize=None)

Bases: object

addButton(button)
addCollider(collider)
addSprite(sprite)
addTrigger(trigger)
draw()
init()
onActive()
onInactive()
removeButton(button)
removeCollider(collider)
removeSprite(sprite)
removeTrigger(trigger)
static sortByBottom(s)
static sortByLeft(s)
static sortByRight(s)
static sortByTop(s)
static sortByZ(s)
update()

pygamepal.splitTexture

pygamepal.splitTexture.splitTexture(texture, newTextureWidth, newTextureHeight)

pygamepal.sprite

class pygamepal.sprite.Sprite(imageName=None, texture=None, position=(0, 0), size=(0, 0), z=0, scaleImage=False, collider=None, trigger=None, drawColor='white')

Bases: Sprite

getCenter()
init()
onAddedToScene()
onRemovedFromScene()
property position
touching(otherSprite)
update()

method to control sprite behavior

Sprite.update(*args, **kwargs):

The default implementation of this method does nothing; it’s just a convenient “hook” that you can override. This method is called by Group.update() with whatever arguments you give it.

There is no need to use this method if not using the convenience method by the same name in the Group class.

property x
property y

pygamepal.spriteImage

class pygamepal.spriteImage.SpriteImage(*textures, state=None, animationDelay=8, loop=True, hFlip=False, vFlip=False, offset=(0, 0), visible=True, alpha=255, pause=False)

Bases: object

Maps states to a ‘SpriteTextureList’ object containing textures and associated info.

addTextures(*textures, state=None, animationDelay=8, loop=True, hFlip=False, vFlip=False, offset=(0, 0))

Add one or more textures to a (new or existing) state.

property alpha
property center
draw(surface, x, y)

Draws the current frame of the current state’s animation. Must be called once per frame.

reset()

Clear object states and textures, and reset the object to default values.

property state
update()

Updates the current sprite animation. Must be called once per frame.

pygamepal.spriteTextureList

class pygamepal.spriteTextureList.SpriteTextureList

Bases: object

Used for storing a list of textures (and other info) for a SpriteImage state.

pygamepal.transition

class pygamepal.transition.Transition(fromSurface=None, toSurface=None, duration=100, drawMethod=None, easingFunction=None)

Bases: object

draw(surface)
reset()
update(deltaTime=1)
class pygamepal.transition.TransitionFade(fromSurface=None, toSurface=None, duration=100, drawMethod=None, easingFunction=<function linear>)

Bases: Transition

draw(surface)
class pygamepal.transition.TransitionFadeToBlack(fromSurface=None, toSurface=None, duration=100, drawMethod=None, easingFunction=None)

Bases: Transition

draw(surface)
class pygamepal.transition.TransitionMoveDown(fromSurface=None, toSurface=None, duration=100, drawMethod=None, easingFunction=None)

Bases: Transition

draw(surface)
class pygamepal.transition.TransitionMoveLeft(fromSurface=None, toSurface=None, duration=100, drawMethod=None, easingFunction=None)

Bases: Transition

draw(surface)
class pygamepal.transition.TransitionMoveRight(fromSurface=None, toSurface=None, duration=100, drawMethod=None, easingFunction=None)

Bases: Transition

draw(surface)
class pygamepal.transition.TransitionMoveUp(fromSurface=None, toSurface=None, duration=100, drawMethod=None, easingFunction=None)

Bases: Transition

draw(surface)
class pygamepal.transition.TransitionWipeDown(fromSurface=None, toSurface=None, duration=100, drawMethod=None, easingFunction=None)

Bases: Transition

draw(surface)
class pygamepal.transition.TransitionWipeLeft(fromSurface=None, toSurface=None, duration=100, drawMethod=None, easingFunction=None)

Bases: Transition

draw(surface)
class pygamepal.transition.TransitionWipeRight(fromSurface=None, toSurface=None, duration=100, drawMethod=None, easingFunction=None)

Bases: Transition

draw(surface)
class pygamepal.transition.TransitionWipeUp(fromSurface=None, toSurface=None, duration=100, drawMethod=None, easingFunction=None)

Bases: Transition

draw(surface)
pygamepal.transition.bounceEaseOut(x)
pygamepal.transition.linear(x)

pygamepal.trigger

class pygamepal.trigger.Trigger(position=(0, 0), size=(10, 10), offset=(0, 0), onEnter=None, onCollide=None, onExit=None, drawColor='yellow')

Bases: object

draw(surface)
property h
update(deltaTime=1)
property w
property x
property y

Module contents