我刚开始一段时间后,有一些问题,有点迷失.
一直在try 用图像作为按钮在Electron 游戏中制作菜单.在看了其他人之后,我模糊了大部分内容,但我认为我犯了一个愚蠢的错误,弄不明白--砍掉了很多行.第一个按钮起作用了,会把你带到正确的菜单,但其他按钮都没有注册.
大多数向导使用绘制来创建按钮,因此没有什么帮助.
我try 移动If\Elif\Else语句,但出现错误或什么都不起作用.
不是真正的程序员,只是想要一些东西来把我们的D&;Dbrew 软件结合在一起--以前使用过TKint,但我想我会试一试.
import pygame
from pygame import mixer
pygame.init()
width=900;
height=800
screen = pygame.display.set_mode( (width, height ) )
pygame.display.set_caption('Chapter 1')
#TownMap = pygame.image.load("Data/images/town.png").convert()
#Button = pygame.image.load("Data/images/buttonsSolo.png").convert_alpha()
def Main_Menu():
Back_Drop = pygame.image.load("Data/images/Art/cursewick1.jpg").convert()
Start_Button = pygame.image.load("Data/Images/UI/Buttons/Start.png").convert_alpha()
Help_Button = pygame.image.load("Data/Images/UI/Buttons/Help.png").convert_alpha()
Exit_Button = pygame.image.load("Data/Images/UI/Buttons/Exit.png").convert_alpha()
screen.blit(Back_Drop, (0,0))
screen.blit(Start_Button , ( 10,10)) # paint to screen
screen.blit(Help_Button , ( 10,110)) # paint to screen
screen.blit(Exit_Button , ( 10,210)) # paint to screen
pygame.display.flip() # paint screen one time
mixer.init()
mixer.music.load("Data\Audio\Music\Intro.mp3")
pygame.mixer.music.set_volume(0.1)
mixer.music.play()
running = True
while (running):
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
# Set the x, y postions of the mouse click
x, y = event.pos
if Start_Button.get_rect().collidepoint(x, y):
print('clicked on image')
pygame.mixer.music.pause()
Town_Map()
if Help_Button.get_rect().collidepoint(x, y):
print('Help')
pygame.mixer.music.pause()
#loop over, quite pygame
pygame.quit()