python - 你如何在 Pygame 中缩放图像?
问题描述
我有一张饼干的照片,它对窗户来说太大了。我尝试过使用,pygame.transform.scale
但无论我尝试哪种尺寸,它都不会按比例放大。这是代码:
import pygame
pygame.init()
window_size = (600, 400)
stage = 0
running = True
font32 = pygame.font.Font('freesansbold.ttf', 32)
font48 = pygame.font.Font('freesansbold.ttf', 48)
red = (255, 0, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
black = (0, 0, 0)
white = (255, 255, 255)
cookieColor = (157, 126, 103)
Window = pygame.display.set_mode(window_size)
pygame.display.set_caption("Cookie Clicker")
windowCenter = (Window.get_rect().centerx, Window.get_rect().centery)
cookieImage = pygame.image.load(r'C:\Users\rogne\Cookie Clicker\Cookie.png')
pygame.transform.scale(cookieImage, (400, 400))
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
if playRect.collidepoint(event.pos) and stage == 0:
stage = 1
if stage == 0:
Window.fill(red)
playbuttontext = font32.render('Play', True, white, red)
playRect = playbuttontext.get_rect()
playRect.centerx = Window.get_rect().centerx
playRect.centery = Window.get_rect().centery + 100
title_text = font48.render('Cookie Clicker', True, white, red)
titleRect = title_text.get_rect()
titleRect.centerx = Window.get_rect().centerx
titleRect.centery = Window.get_rect().centery - 100
Window.blit(playbuttontext, playRect)
Window.blit(title_text, titleRect)
if stage == 1:
Window.fill(black)
Window.blit(cookieImage, (200, 200))
pygame.display.update()
pygame.quit()
解决方案
推荐阅读
- fuzzing - AFL hello world 示例
- arrays - 在ruby中对数字和字符串数组进行排序的有效方法?
- eclipse - 我在哪里可以学习如何以编程方式将项目导入 Eclipse?
- java - 显示对象数组列表,在 TableView 的对象数组列表内
- gradle - Gradle jlink 选项给出访问权限警告
- sql - 使用循环 postgres 更新表数据
- list - 我需要存储为地理位置列表的道路数据
- r - ggplot2 中 PCA 分数的 Facetgrid
- python-3.x - 在 Tensorboard 中使用 Tensorflow v2.0 显示图形
- javascript - 页面未使用本地存储更新