| 
 | 
 
 
发表于 2022-5-21 09:29:16
From FishC Mobile
|
显示全部楼层
|阅读模式
 
 
 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
错误代码 
import pygame 
import sys 
pygame.init() 
 
size = width,height = (950,600) 
 
pygame.display.set_caption('测试') 
screen = pygame.display.set_mode(size) 
 
background = pygame.image.load('images/地图.png') 
 
class Player: 
    def __int__(self): 
        self.image = pygame.image.load('111.png') 
        self.rect = self.image.get_rect() 
 
player = Player()  
FPS = 60 
clock = pygame.time.Clock() 
while True: 
    screen.blit(background,(0,0)) 
    screen.blit(player.image,player.rect) 
 
    for a in pygame.event.get(): 
        if a.type == pygame.QUIT: 
            pygame.quit() 
            sys.exit() 
    clock.tick(FPS) 
    pygame.display.update()  
 
报错原因,运行不起来Traceback (most recent call last): 
  File "E:\Python\game\测试.py", line 24, in <module> 
    screen.blit(player.image,player.rect) 
AttributeError: 'Player' object has no attribute 'image' 
 检查过self.image的图片路径,没有问题,改过图片名字,改过image变量名,一直不行,是不是某个地方插件有问题? 
求解惑!
 
认真看回复嗷,不是下划线问题,是 __init__ 不是 __int__ 
 
 
 |   
 
 
 
 |