Я просто хочу, чтобы изображение стало меньше, подождите четверть секунды, а затем снова станет больше, но с самого начала оно никогда не становится маленьким. Я протестировал этот фрагмент кода без кода, чтобы снова сделать его большим, это работает, но когда я добавляю код, чтобы снова сделать его большим, он перестает работать. Должен отметить, что я новичок в 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
Как мне правильно масштабировать изображение в pygame ⇐ Python
Программы на Python
-
Anonymous
1736912302
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()
Подробнее здесь: [url]https://stackoverflow.com/questions/79357010/how-do-i-make-my-image-scale-properly-in-pygame[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия