2017-11-08 1 views
-3

파이 게임으로 게임을 만들려고합니다. 클릭 할 때 이미지가 나타나게하고 싶지만 그 기능을 프로그래밍하는 방법을 모르겠습니다.이미지가 파이 게임에 표시됩니다.

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() 

답변

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() 
관련 문제