Pygame:
pygame是一个设计用来开发游戏的python模块,在SDL库的基础上提供了各种接口,从而使用用户能够使用python语言创建各种各样的游戏或多媒体程序。
我的理解:能够使用python开发出2D游戏的工具!Pygame,fly me to the moon!
http://pygame.org/docs/ref/draw.html
Hello,Pygame:
# !.usr/bin/python
# -*- coding:utf-8 -*-
# author: by qiu
# time: 2015-1-30
import sys
import pygame
from pygame.locals import *
pygame.init()
#重要常量
SCREEN_SIZE = (640, 480)
background_file = "background.jpg"
hello_file = "hello.gif"
Runing = True
pygame.display.set_caption("Hello, World!")
screen = pygame.display.set_mode(SCREEN_SIZE, 0, 32) # 分辨率, 窗口标识, 色度
background = pygame.image.load(background_file).convert()
mouse_cursor = pygame.image.load(hello_file).convert_alpha()
while Runing:
for event in pygame.event.get():
if event.type == pygame.QUIT: #关闭窗体
pygame.quit()
sys.exit()
screen.blit(background, (0, 0))
x, y = pygame.mouse.get_pos() #获取鼠标位置
x -= mouse_cursor.get_width() /2
y -= mouse_cursor.get_height() /2 #计算光标左上角位置
screen.blit(mouse_cursor, (x, y)) # 画上光标
pygame.display.update() #刷新屏幕 显示
总结:
窗体+事件循环