Pygame学习笔记(五)

# 显示动画
import pygame

# 初始化
pygame.init()
new_image = pygame.image.load('Jennifer.png')
screen_width = 400  # 窗口的宽度
screen_height = 600  # 窗口的高度
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption('动画显示')
screen.fill((255, 255, 255))
pygame.display.flip()

# 1.显示静态球
y = 100
r = 100
ix, iy = 100, 100
d = 1
pygame.draw.circle(screen, (0, 255, 255), (100, y), r)
pygame.display.update()

# 游戏循环
num = 1

while True:
    num += 1
    # # 1)移动动画
    # if num % 10 == 0:
    #     pygame.draw.circle(screen, (255, 255, 255), (100, y), 50)
    #     y += 1      # 改变球y坐标, 形成移动效果
    #     pygame.draw.circle(screen, (0, 255, 255), (100, y), 50)
    #     pygame.display.update()

    # # 2)缩放动画
    # if num % 10 == 0:
    #     pygame.draw.circle(screen, (255, 255, 255), (100, y), r)
    #     r -= 1      # 改变球y坐标, 形成移动效果
    #     pygame.draw.circle(screen, (0, 255, 255), (100, y), r)
    #     pygame.display.update()

    # # 3)旋转动画
    # if num % 10 == 0:
    #     screen.fill((255, 255, 255))
    #     d += 1
    #     new_image1 = pygame.transform.rotozoom(new_image, d, 1)
    #     screen.blit(new_image1, (ix, iy))
    #     pygame.display.update()

    # 4)移动和缩放
    if num % 10 == 0:
        pygame.draw.circle(screen, (255, 255, 255), (100, y), r)
        screen.blit(new_image, (ix, iy))
        y += 4
        r += 1
        pygame.draw.circle(screen, (255, 0, 0),  (100, y), r)
        pygame.display.update()


    # 检测事件
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值