Presentation is loading. Please wait.

Presentation is loading. Please wait.

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,

Similar presentations


Presentation on theme: "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,"— Presentation transcript:

1 Meet Pygame Noah Kantrowitz June 8, 2007

2 The Basics Cross-platform Based on SDL (don’t quote me on that) Handle input (keyboard, mouse) and output (graphics, audio)

3 Starting Up import pygame pygame.init() Cue music...

4 The Screen screen = pygame.display.set_mode((x, y)) screen = pygame.display.get_surface() pygame.display.flip() pygame.display.update(dirty)

5 Surfaces The basic element of graphics pygame.image.load(file).convert_alpha() vs.set_colorkey((r,g,b)) dest.blit(src, (x, y))

6 Formats Native support for the following: SVG will need to worked out Stay tuned... JPEGPNGGIFBMPPCX TGATIFLBMPBMXPM

7 The Loop while True:

8 The Loop while True:

9 Timing from pygame.time import Clock clock = Clock() delta = clock.tick(30)

10 The Loop while True:

11 Event Handling for evt in pygame.event.get(): if evt.type == pygame.QUIT: sys.exit()...

12 Event Handling Other types: QUITKEYUPKEYDOWN MOUSEMOTIONMOUSEBUTTONUPMOUSEBUTTONDOWN

13 Key Events evt.key == pygame.K_a See the Pygame documentation for the full list of key constants.

14 Mouse Events evt.pos evt.button (for the button events)

15 The Loop while True:

16 Sprites pygame.sprite.Sprite class Foo(Sprite): Must call superclass __init__().image,.rect

17 Groups pygame.sprite.Group RenderUpdates, OrderedUpdates.add(),.remove().update(*args) More on these in a moment

18 The Loop while True:

19 Drawing.draw(dest) Dirty updates pygame.draw.update(dirty)

20 Rects pygame.Rect(left,top,width,height) surf.get_rect() Always at (0,0) Attributes: topbottomleftrighttopleftbottomleft toprightbottomrightmidtopmidbottommidleftmidright centercenterxcenterysizewidthheight

21 Collisions Rect-based spritecollide(sprite,group,kill) spritecollideany(sprite,group) groupcollide(group1,group2,kill1,kill2)

22 Sound pygame.mixer.Sound(file).play(),.stop() pygame.mixer.music

23 Text Try to avoid it for now.

24 More? http://www.pygame.org/docs Email me. (noah@laptop.org)noah@laptop.org


Download ppt "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,"

Similar presentations


Ads by Google