Как мне правильно масштабировать изображение в pygamePython

Программы на Python
Ответить
Anonymous
 Как мне правильно масштабировать изображение в pygame

Сообщение Anonymous »

Я просто хочу, чтобы изображение стало меньше, подождите четверть секунды, а затем снова станет больше, но с самого начала оно никогда не становится маленьким. Я протестировал этот фрагмент кода без кода, чтобы снова сделать его большим, это работает, но когда я добавляю код, чтобы снова сделать его большим, он перестает работать. Должен отметить, что я новичок в pygame.
import pygame

import sys

import time

pygame.init()

global points

global ppc

upgrades = ["up1"]

points = 0

ppc = 1

timevar1 = 0
# initializing the constructor
pygame.init()

# screen resolution
res = (1840,1000)

# opens up a window
screen = pygame.display.set_mode(res)

# white color
white = (255,255,255)

# light shade of the button
dark_gray = (100,100,100)

light_gray = (170,170,170)

white = (255,255,255)

walnut = (138, 88, 47)

black = (0, 0, 0)

walnut_image = pygame.image.load(r"C:/Users/spencer/Downloads/walnut.jfif")

walnut_image = pygame.transform.scale(walnut_image, (400, 600))

image_rect = walnut_image.get_rect()

image_rect.center = (300,400)
# stores the width of the
# screen into a variable
width = screen.get_width()

# stores the height of the
# screen into a variable
height = screen.get_height()

# defining a font
smallfont = pygame.font.SysFont('arial',35)

# rendering a text written in
# this font
def count_digits(number):

number_str = str(number)

return len(number_str)

def draw_button(text, x, y, color1, color2):

text_surface = smallfont.render(text, True, white)

text_width, text_height = smallfont.size(text)

padding = 20 # Add some padding around the text

button_width = text_width + padding * 2

button_height = text_height + padding

button_rect = pygame.Rect(x, y, button_width, button_height)

pygame.draw.rect(screen, color1, button_rect)

pygame.draw.rect(screen, color2, button_rect, 2) # Border

screen.blit(text_surface, (x + padding, y + padding / 2))

return button_rect

running = True
while running:

mouse_pos = pygame.mouse.get_pos()

screen.fill((30,30,30)) # Background color

screen.blit(walnut_image,image_rect)

button_text = f"{points}"

button1 = draw_button(button_text, 250, 800,walnut, black)

if button1.collidepoint(mouse_pos):

pygame.draw.rect(screen, light_gray, button1)

pygame.draw.rect(screen, light_gray, button1, 2)

for event in pygame.event.get():

if event.type == pygame.QUIT:

running = False
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: # Left mouse button

if button1.collidepoint(event.pos):

walnut_image = pygame.transform.scale(walnut_image,(200,300))

image_rect = walnut_image.get_rect()

image_rect.center = (300,400)

pygame.time.delay(250)

walnut_image = pygame.transform.scale(walnut_image,(400,600))

image_rect = walnut_image.get_rect()

image_rect.center = (300,400)

points += 1 # Increment the click count

pygame.display.update()


Подробнее здесь: https://stackoverflow.com/questions/793 ... -in-pygame
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»