【发布时间】:2021-11-09 12:10:27
【问题描述】:
所以我正在为 sea jam 制作一个游戏,并且我一直在运行我的两个按钮时遇到这个错误,我认为它不是函数或类之一,但如果它是请分享我需要在 29 日之前完成这个,这是我的第一次果酱,这里是代码:
import pygame
sh = 400
sw = 400
pygame.font.init() # you have to call this at the start,
# if you want to use this module.
screen = pygame.display.set_mode((sh, sw))
b = pygame.image.load("b.png").convert_alpha()
ub = pygame.image.load("ub.png").convert_alpha()
scr = 0
class ubut():
def __init__(self,x,y,image):
self.image = image
self.rect = self.image.get_rect()
self.rect.topleft = (x, y)
def draw(self):
screen.blit(self.image, (self.rect.x, self.rect.y))
mpos = pygame.mouse.get_pos()
global scr
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONUP:
if self.rect.collidepoint(mpos):
print("x")
class but():
def __init__(self,x,y,image):
self.image = image
self.rect = self.image.get_rect()
self.rect.topleft = (x, y)
def draw(self):
screen.blit(self.image, (self.rect.x, self.rect.y))
mpos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONUP:
if self.rect.collidepoint(mpos):
global scr
scr += 1
print(scr)
def redb(self):
mpos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONUP:
if self.rect.collidepoint(mpos):
global scr
scr += 1
print(scr)
def purpb(self):
mpos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONUP:
if self.rect.collidepoint(mpos):
print("x")
buttton = but(125,125 , b)
ubutton = but(125,225,ub)
run = True
while run:
screen.fill((0,255,0))
ubutton.purpb()
ubutton.draw()
buttton.draw()
buttton.redb()
mpos = pygame.mouse.get_pos()
pygame.display.update()
感谢您的帮助。
【问题讨论】: