猫史档案馆


教程~pygame-2

用户:萌新大佬萌新大佬查看:0 回复:3 评论:0 创建时间:2020-05-06T13:49:24


欢迎继续学习pygame,咱们接着讲。

今天学习移动位置以及切换造型

 

 

1.切换角色

图片在此

center_image

很简单

打代码

import pygame

pygame.init()
pygame.display.set_caption("切换角色")
keep_going = True

pic = pygame.image.load("雷电猴.png")
pic2 = pygame.image.load("编程猫.png")
pic_list = [pic, pic2]

cnt = 0
timer = pygame.time.Clock()

while keep_going:
    screen = pygame.display.set_mode([400, 400])
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            keep_going = False
    screen.blit(pic_list[cnt%2], (0, 0))
    pygame.display.update()

pygame.quit()

利用cnt来切换图片然后刷新center_image

好快!!!!

加代码

import pygame

pygame.init()
pygame.display.set_caption("源码变变变")
keep_going = True

pic = pygame.image.load("雷电猴.png")
pic2 = pygame.image.load("编程猫.png")
pic_list = [pic, pic2]

cnt = 0
timer = pygame.time.Clock()
#设置时钟

while keep_going:
    screen = pygame.display.set_mode([400, 400])
    bg_color = (0, 0, 0)
    screen.fill(bg_color)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            keep_going = False
    screen.blit(pic_list[cnt % 2], (0, 0))
    pygame.display.update()
    cnt += 1
    timer.tick(2)
    #每秒两帧

pygame.quit()

好多了center_image

现在让图片移动

import pygame

pygame.init()
pygame.display.set_caption("源码变变变")
keep_going = True

pic = pygame.image.load("雷电猴.png")
pic2 = pygame.image.load("编程猫.png")
pic_list = [pic, pic2]

cnt = 0
timer = pygame.time.Clock()

x = 0

speed_x = 0.2

while keep_going:
    screen = pygame.display.set_mode([400, 400])
    bg_color = (0, 0, 0)
    #背景颜色    R  G  B
    screen.fill(bg_color)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            keep_going = False
    screen.blit(pic_list[cnt % 2], (x, 0))
    pygame.display.update()
    cnt += 1
    timer.tick(2)
    x += speed_x
    pygame.quit()

center_image

搞定,┏(^0^)┛byebye


回复

上一页1 页 / 共 1下一页
D453D453

赞赞赞!

点赞1


评论


名字是什么a名字是什么a

emotion_编程猫_点赞

点赞1


评论


萌新大佬萌新大佬

谢谢支持

点赞0


评论