Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Pygame

A quick introduction to pygame - might evolve to something more one day
by

Mike Reilly

on 19 December 2012

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Pygame

Pygame Put Pictures on screen! import pygame Surface a quick introduction Conclusion is here To use pygame, you have to first install it, then add one
or more imports You need a window for your program. To do this, create a surface from pygame.display! BLIT, or bit block transfer, is how we put pictures on screen - basically copy them from one surface to another. Pygame makes this pretty easy! zoom in, and add details to these Frames import pygame
from pygame.locals import * myWindow=pygame.display.set_mode((640,480))
This creates a window 640 by 480
Use the myWindo object (or whatever you decide to call it, it's up to you) to then draw (blit) things onto the screen. myWindow is now the name of the window created with set_mode. First you need to load a picture to an off screen surface:
myPic=pygame.image.load('Wall.png')

BUT, if you have a picture that has transparency, you need to add conver_alpha() on the end:
myPic=pygame.image.load('Wall.png').convert_alpha() Next, you need a Rect object, which holds the x and y position, as well as the width and height of an image:
myRect=myPic.get_rect()
Let's give the image a position on screen before we blit it:
myRect.left=100
myRect.top=120 And finally, let's copy (or blit) the image:
myWindow.blit(myPic,myRect)
pygame.display.update()

You need the last line to update the display on screen
otherwise no changes will be shown since your last update() So what? You might be thinking right now, so what? This just put's a picture at a spot on the screen. How does that make a video game? It doesn't really. Now you need to be clever and use loops to display things on screen - to draw a single screen made up of tiles like my dungeon game, or to draw a screen with a character on it that changes position based on what key you press or whatever. We'll look at these techniques next! This is the full code from our lesson so far:

import pygame
from pygame.locals import *

myWindow=pygame.display.set_mode((640,480))
myPic=pygame.image.load('Hero1.png').convert_alpha()
myRect=myPic.get_rect()
myRect.left=100
myRect.top=120
myWindow.blit(myPic,myRect)
pygame.display.update()
Full transcript