我试图用pygame制作游戏,我想在点击时显示图像,但我不知道如何编写该功能。
import pygame, sys, time, os
pygame.init()
windowImg = pygame.display.setmode((800,600))
pygame.display.set_caption("Videogame 001")
clock = pygame.tima.Clock()
landerImg = Pygame.image.load("C:\RedSquare.jpg")
landerX = 200
landerY= 200
while True:
clock.tick(15)
for event in pygame.even.get():
if event.type == pygame.QUIT
pygame.display.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
pygame.draw(landerImg)
#this is the part of the code where i do not know ho to make an image appear when I click
pygame.display.flip()
答案 0 :(得分:1)
import pygame, sys, time, os
pygame.init()
windowImg = pygame.display.set_mode((800,600))
pygame.display.set_caption("Videogame 001")
clock = pygame.time.Clock()
landerImg = pygame.image.load("C:\\RedSquare.jpg")
landerX = 200
landerY= 200
while True:
clock.tick(15)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.display.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
#this is the solution to your problem
windowImg.blit(landerImg,(landerX ,landerY))
#######################
pygame.display.flip()