2017-05-22 95 views
0
import pygame 

pygame.init() 

screen=pygame.display.set_mode([800,600]) 

gameon = True 

bgcolor=pygame.color.Color('#ffe39b') 

gen=pygame.image.load("N:\python\installed files\images\gen.png") 

gen_small= pygame.transform.scale(gen,(90,90)) 

black= ([0,0,0]) 

white= ([255,255,255]) 

bus1=pygame.rect.Rect(225,100,15,100) 

bus2=pygame.rect.Rect(350,450,100,15) 

bus3=pygame.rect.Rect(500,100,15,100) 

dx=-200 

dy=-200 

dx2=-300 

dy2=-300 

#make a button 

genbut=pygame.image.load("N:\python\installed files\images\genbut.png") 

busbut=pygame.image.load("N:\python\installed files\images\elecbusbut.png") 

linebut=pygame.image.load("N:\python\installed files\images\linebut.png") 

motorbut=pygame.image.load("N:\python\installed files\images\motorbut.png") 

loadbut=pygame.image.load("N:\python\installed files\images\loadbut.png") 

imagepass=False 

i=0 

while gameon: 


genbutzone=genbut.get_rect() 
genbutzone.x=400 
genbutzone.y=0 
screen.blit(gen_small,(600,100)) 
screen.blit(genbut,(400,0)) 

screen.blit(busbut,(100,0)) 
screen.blit(motorbut,(600,0)) 
screen.blit(loadbut,(300,0)) 
screen.blit(linebut,(200,0)) 
screen.blit(gen_small,(350,500)) 

pygame.draw.rect(screen,black,bus1) 

pygame.draw.rect(screen,black,bus2) 

pygame.draw.rect(screen,black,bus3) 
pygame.display.flip() 

event = pygame.event.poll() 
mx,my=pygame.mouse.get_pos() 
if genbutzone.collidepoint(mx,my) and event.type== pygame.MOUSEBUTTONDOWN: 
    imagepass=True 
    print("i hit") 
if event.type==pygame.MOUSEBUTTONDOWN and not genbutzone.collidepoint(mx,my): 

    print("hi") 
    imagepass=False 
    i=i+1 

if imagepass==True and event.type==pygame.MOUSEMOTION and i==0: 
    dx,dy= pygame.mouse.get_pos() 
if imagepass== True and event.type==pygame.MOUSEMOTION and i==1: 
    dx2,dy2= pygame.mouse.get_pos() 

screen.blit(gen_small,(dx,dy)) 
screen.blit(gen_small,(dx2,dy2))  
pygame.display.flip() 
screen.fill(bgcolor)  

pygame.quit() 

quit() 
+3

請編輯您的問題以提供[最小,完整和可驗證示例](https://stackoverflow.com/help/mcve)。你也應該提出一個問題。只是在這裏放一些代碼不會幫助人們理解你的問題。 – MrLeeh

回答

0

請花時間制定一個真正的問題,並設置您的代碼的格式。這並不困難。

話雖如此,就我所見,您的問題是多次致電pygame.display.flip()

確保在遊戲循環中首先清理屏幕(screen.fill(bgcolor)),然後完成所有繪圖,然後調用pygame.display.flip()pygame.display.update()一次。