找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3757|回复: 2

[求助] AttributeError: 'pygame.Surface' object attribute 'blit' is read-only

2

主题

7

帖子

7

积分

贫民

积分
7
learning 发表于 2018-1-4 10:25:46 | 显示全部楼层 |阅读模式
import pygame

class Ship():
    def __init__(self, screen):
        self.screen = screen
        self.i = pygame.image.load('images/1.bmp')
        self.s = self.i.get_rect()
        self.screen_rect = screen.get_rect()

        self.s.centerx = self.screen_rect.centerx
        self.s.bottom = self.screen_rect.bottom

        self.moving_right = False
        self.moving_left = False

    def update(self):
        if self.moving_right and self.s.right < self.screen.rect.right:
            self.s.centerx += 1
        elif self.moving_left and self.s.right > 0:
            self.s.centerx -= 1

    def plant(self):
        self.screen.blit = (self.i, self.s)


运行主函数显示
self.screen.blit = (self.i, self.s)
AttributeError: 'pygame.Surface' object attribute 'blit' is read-only
是什么问题?如何解决?求助各位大佬~

回复

使用道具 举报

2

主题

219

帖子

219

积分

版主

Rank: 7Rank: 7Rank: 7

积分
219

热心会员默默耕耘优秀版主

剑心无痕 发表于 2018-1-4 10:46:15 | 显示全部楼层
screen.blit(background,(0,0))     #将背景图画上去,blit是个重要函数,第一个参数为一个Surface对象,第二个为左上角位置

blit是函数,是screen的只读属性,不可以被更改,只能调用
回复 支持 反对

使用道具 举报

2

主题

7

帖子

7

积分

贫民

积分
7
learning  楼主| 发表于 2018-1-4 12:04:35 | 显示全部楼层
剑心无痕 发表于 2018-1-4 10:46
screen.blit(background,(0,0))     #将背景图画上去,blit是个重要函数,第一个参数为一个Surface对象,第 ...

明白了~谢谢版主大大
回复 支持 反对

使用道具 举报

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

本版积分规则

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