Skip to main content

CookBook — wiki

def show_cook_book_love(screen):
    txt = "I love the CookBook!"
    f = SysFont("Arial", 12)
    s = f.render(txt, 1, (0,0,0))
    screen.blit(s, (0,0))

Posting A Recipe:

  • Please start a new page for each recipe.
  • Use the <pre><code>YOUR CODE</code></pre> tags to put in code.(View source of some other pages to see how it is done.)
  • Except where otherwise noted, recipes posted in the pygame cookbook are in public domain.
  • Tabs are lost when posting, so convert tabs to spaces first if you use them.

Generic recipes

Profiling
RunningInCorrectDirectory
LinearInterpolator
SmoothInterpolator
BoundingBox
2DVectorClass
3DVectorClass
CommandDispatch (A pattern for building GUIs)
2DGeometryEngine
QuadTree
MemoizingDecorator (Another lazy resource loader)
SignalSlot (A signal/slot implementation)
Interpolator (An improved interpolator)
BezierCurve
RGBColorConversion
CalculateDist
SpatialHashMap
ConstantGameSpeed

PyGame recipes

LazyImageLoading
SimpleFontManager
TTFToBitmapConverter
toggle_fullscreen
Joystick_analyzer
ImagePacker
SmallerRectForSpriteCollision
GradientCode
ConchMusicSoundToolkit
FastPixelPerfect
SettingWindowPosition
DummyVideoDriver
WindowResizing
TextWrapping
CairoPygame
Load_32-bit_BMP_with_Alpha
HeadlessNoWindowsNeeded (Use pygame without using creating a window)
SubtractRects
ShadowEffects (Using arrays)
MatplotlibPygame
IntersectingLineDetection
MmapSurfaces
WxPython
Pygame2exe
InputWrapper
RotateCenter
MidiScheduler
SpatialHash_for_Pygame
Spritesheet
Tint
SoundGeneration
DrawWaveform

PyOpenGL recipes

SimpleOpenGL2dClasses
OBJFileLoader
GLLight
GLSLExample
GLSL_ARB_Example
TextureCoordinateArithmetic
MakeOpenglDrawIn2D
CrossPlatformTextOpengl