DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Comparing Pygame And Pys60

02.10.2006
| 5086 views |
  • submit to reddit
        I take the pygame code from <a href=http://rene.f0o.com/mywiki/LectureThree>here</a>. Then, write my own pys60 part.
# pygame's typical beginning
import pygame
from pygame.locals import *

# pys60
import e32, graphics
from appuifw import *
Setting up the screen
# pygame
window = pygame.display.set_mode((468, 60)) 

# pys60
app.screen = 'full'   # or 'normal', 'large'
Get screen or canvas
# pygame
screen = pygame.display.get_surface() 

# pys60
app.body = canvas = Canvas(None, key.handle_event) 
# you need to create key (a Keyboard instance) before this
Loading image
# pygame
monkey_image = pygame.image.load(file_name)

# pys60
monkey_image = graphics.Image.open(file_name)
Drawing image onto the screen
# pygame
screen.blit(monkey_image, (0,0))
pygame.display.flip()  

# pys60
canvas.blit(monkey_image, target=(0,0))
# we may add a buffer, which will need buffer.blit(image)
# and canvas.blit(buffer) for equivalent steps
Loading and playing sound
# pygame
sound = pygame.mixer.Sound(fullname)
sound.play()

# pys60
import audio
sound = audio.Sound.open(fullname)
sound.play()

For Rect and Sprite, there is no pys60 equivalence yet.
I may write an equivalent class someday.