鱼C论坛

 找回密码
 立即注册
查看: 705|回复: 3

[已解决]小白求助

[复制链接]
发表于 2018-7-26 09:51:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
这是报错所在的py文件的代码:
import pygame


class Bullet1(pygame.sprite.Sprite):
    def __init__(self, position):
        pygame.sprite.Sprite.__init__(self)


        self.image = pygame.image.load('Images1/bullet1.png').convert_alpha
        self.rect =self.image.get_rect()
        self.rect. left, self.rect.top = position
        self.speed = 12
        self.active = True
        self.mask = pygame.mask.from_surface(self.image)


    def move(self):
        self.rect.top -= self.speed

        if self.rect.top < 0:
            self.active = False

    def reset(self, position):
        self.rect.left, self.rect.top = position
        self.active = True

这是错误提示:
File "C:\Users\asus\Desktop\bullet.py", line 10, in __init__
    self.rect = self.image.get_rect()
AttributeError: 'builtin_function_or_method' object has no attribute 'get_rect'


   
最佳答案
2018-7-27 09:42:29
树与鲸与你 发表于 2018-7-27 09:39
感谢你的回答,但是get_rect是他内置的,是已经定义好了的。我通过一个晚上的对比小甲鱼代码总算发现是我 ...

请结贴~~
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-7-26 09:55:53 | 显示全部楼层
你没有定义get_rect,然后在后面你又调用。。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-7-27 09:39:47 | 显示全部楼层
无符号整形 发表于 2018-7-26 09:55
你没有定义get_rect,然后在后面你又调用。。

感谢你的回答,但是get_rect是他内置的,是已经定义好了的。我通过一个晚上的对比小甲鱼代码总算发现是我的上一行缺了一个(),致使python无法使用get_rect
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-7-27 09:42:29 | 显示全部楼层    本楼为最佳答案   
树与鲸与你 发表于 2018-7-27 09:39
感谢你的回答,但是get_rect是他内置的,是已经定义好了的。我通过一个晚上的对比小甲鱼代码总算发现是我 ...

请结贴~~
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-9 03:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表