首页 > 编程语言 > 详细

python学习pygame

时间:2019-03-30 10:24:24      阅读:137      评论:0      收藏:0      [点我收藏+]

基本库导入

import pygame
import sys
from pygame.locals import *

 

初始化

pygame.init()

 

窗口标题

pygame.display.set_caption("初次见面多多关照")

 

窗口显示设置

screen = pygame.display.set_mode(size, RESIZABLE)

resizable可选参数,设定窗口能否拖动变形

screen = pygame.display.set_mode((1680, 1050), FULLSCREEN | HWSURFACE)

全屏设置

 

图像导入

turtle = pygame.image.load("turtle.png")

 

图像范围获得一个矩形

turtle_rect = turtle.get_rect()

用于碰撞检测

 

图像旋转翻转

turtle_right = pygame.transform.rotate(turtle, 90)

r_head = pygame.transform.flip(turtle, True, False)

 

事件检测,包括退出,按键,鼠标等事件

for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                XXX

 

移动位置
    position = position.move(speed)

 

    screen.fill(bg)   背景填充
    screen.blit(turtle, position)  #更新图像
    pygame.display.flip()       #更新界面

    pygame.time.delay(10)   延迟10ms

 

python学习pygame

原文:https://www.cnblogs.com/jdzhang1995/p/10625386.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!