pygame

作者: 苏鑫的博客 | 来源:发表于2017-09-19 21:03 被阅读0次

学习pygame如果不了解pygame是什么的可以参考百度或者去官网去看介绍pygame急忙趁着三分的热度,整理一下关于pygame的相关内容,顺便复习一下Markdown编辑器

所以根据pygame的文档教程进行学习,学习的最好方法就是制作实例

    #-*-coding:utf-8-*-
    import sys, pygame
    pygame.init()                    #加载模块列表

    size = width, height = 720,640          #等同于size = width,height = (320,240)官网里文档的屏幕太小所以我们改变一下大小
    speed = [2, 2]
    black = 0, 0, 0

    screen = pygame.display.set_mode(size)       #建立一个size大小的graphical window(绘画窗口)

    ball = pygame.image.load("ball.bmp")        
    ballrect = ball.get_rect()                    #获取rect object

    while 1:
        for event in pygame.event.get():                #获取事件
            if event.type == pygame.QUIT: sys.exit()
    
        ballrect = ballrect.move(speed)
        if ballrect.left < 0 or ballrect.right > width:
            speed[0] = -speed[0]
        if ballrect.top < 0 or ballrect.bottom > height:
           speed[1] = -speed[1]

        screen.fill(black)
        screen.blit(ball, ballrect)   #blit基本上意味着将像素颜色从一个图像复制到另一个图像。我们通过blit方法将源Surface复制,并将源放置在目标位置.
        pygame.display.flip()                #更新可见显示

因为始终没找到一款好用合适的录屏软件所以只能添加静态图了


相关文章

  • 2018-09-04-pygame

    一、pygame基本操作 import pygame——导入pygame模块 pygame.init()——初始化...

  • Pygame入门--飞机大战案例

    Pygame的快速入门 #导入pygame模块 import pygame #游戏初始化 pygame.init(...

  • Day_10 异常与pygame

    异常捕获 pygame操作流程 pygame显示文字 pygame显示图片与图片操作 pygame基本显示

  • Pygame-hello world

    使用pygame 模块名功能pygame.cdrom访问光驱pygame.cursors加载光标pygame.di...

  • pygame - alphabet

    pygame install pygame install[https://www.pygame.org/wiki...

  • Day12 pygame

    1.pygame基本操作: 1.导入pygame: import pygame.2.初始化:pygame init...

  • Day-18正则表达式2

    pygame游戏基本框架的创建 pygame中图片的显示 字体的显示 图形 Pygame Pygame有很多的模块...

  • day11-pygame笔记

    1pygame事件 import pygame pygame.display.set_caption('游戏事件'...

  • Python——Pygame模块

    学习资料: Pygame官网 pygame系列 PyGame - Python Wiki 用Python和Pyga...

  • pygame简介

    简介 关于Pygame的基本信息,pygame是什么,谁会被Pygame吸引,并且在哪里找到它。 Pygame是被...

网友评论

    本文标题:pygame

    本文链接:https://www.haomeiwen.com/subject/dgmgsxtx.html