meet pygame
Download
Skip this Video
Download Presentation
Meet Pygame

Loading in 2 Seconds...

play fullscreen
1 / 24

Meet Pygame - PowerPoint PPT Presentation


  • 119 Views
  • Uploaded on

Meet Pygame. Noah Kantrowitz June 8, 2007. The Basics. Cross-platform Based on SDL (don’t quote me on that) Handle input (keyboard, mouse) and output (graphics, audio). Starting Up. import pygame pygame.init() Cue music. The Screen. screen = pygame.display.set_mode((x, y))

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Meet Pygame' - brendan-huber


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
meet pygame
Meet Pygame
  • Noah Kantrowitz
  • June 8, 2007
the basics
The Basics
  • Cross-platform
  • Based on SDL (don’t quote me on that)
  • Handle input (keyboard, mouse) and output (graphics, audio)
starting up
Starting Up
  • import pygame
  • pygame.init()
  • Cue music ...
the screen
The Screen
  • screen = pygame.display.set_mode((x, y))
  • screen = pygame.display.get_surface()
  • pygame.display.flip()
  • pygame.display.update(dirty)
surfaces
Surfaces
  • The basic element of graphics
  • pygame.image.load(file)
  • .convert_alpha() vs .set_colorkey((r,g,b))
  • dest.blit(src, (x, y))
formats

JPEG

PNG

GIF

BMP

PCX

TGA

TIF

LBM

PBM

XPM

Formats
  • Native support for the following:
  • SVG will need to worked out
  • Stay tuned ...
the loop
The Loop
  • while True: <timing> <event handling> <update phase> <draw phase>
the loop1
The Loop
  • while True:<timing> <event handling> <update phase> <draw phase>
timing
Timing
  • from pygame.time import Clock
  • clock = Clock()
  • delta = clock.tick(30)
the loop2
The Loop
  • while True: <timing><event handling> <update phase> <draw phase>
event handling
Event Handling
  • for evt in pygame.event.get(): if evt.type == pygame.QUIT: sys.exit() ...
event handling1

QUIT

KEYUP

KEYDOWN

MOUSEMOTION

MOUSEBUTTONUP

MOUSEBUTTONDOWN

Event Handling
  • Other types:
key events
Key Events
  • evt.key == pygame.K_a
  • See the Pygame documentation for the full list of key constants.
mouse events
Mouse Events
  • evt.pos
  • evt.button (for the button events)
the loop3
The Loop
  • while True: <timing> <event handling><update phase> <draw phase>
sprites
Sprites
  • pygame.sprite.Sprite
  • class Foo(Sprite):
  • Must call superclass __init__()
  • .image, .rect
groups
Groups
  • pygame.sprite.Group
  • RenderUpdates, OrderedUpdates
  • .add(), .remove()
  • .update(*args)
  • More on these in a moment
the loop4
The Loop
  • while True: <timing> <event handling> <update phase><draw phase>
drawing
Drawing
  • .draw(dest)
  • Dirty updates
  • pygame.draw.update(dirty)
rects

top

bottom

left

right

topleft

bottomleft

topright

bottomright

midtop

midbottom

midleft

midright

center

centerx

centery

size

width

height

Rects
  • pygame.Rect(left,top,width,height)
  • surf.get_rect()Always at (0,0)
  • Attributes:
collisions
Collisions
  • Rect-based
  • spritecollide(sprite,group,kill)
  • spritecollideany(sprite,group)
  • groupcollide(group1,group2,kill1,kill2)
sound
Sound
  • pygame.mixer.Sound(file)
  • .play(), .stop()
  • pygame.mixer.music
slide23
Text
  • Try to avoid it for now.
slide24
More?
ad