color属性 python_'游戏。表面'object没有'color'属性'

所以,我的问题是,我试图画一个矩形,但我一直得到一个错误,说'pygame.Surface' object has no attribute 'color'。有人能帮我吗?在

完整错误消息Traceback (most recent call last):

File "main.py", line 64, in

game.new()

File "main.py", line 23, in new

self.run()

File "main.py", line 32, in run

self.draw()

File "main.py", line 55, in draw

self.snake.draw(self.screen)

File "C:\Users\sidna\Dropbox\Dev Stuff\Games\Snake\sprites.py", line 15, in draw

pygame.draw.rect(screen, self.color

AttributeError: 'pygame.Surface' object has no attribute 'color'

精灵.py

^{pr2}$

主.pyfrom settings import *

from sprites import *

import pygame

import random

class Game:

def __init__(self):

# initialize game window, etc

pygame.init()

pygame.mixer.init()

self.screen = pygame.display.set_mode((WIDTH, HEIGHT))

pygame.display.set_caption(TITLE)

self.clock = pygame.time.Clock()

self.running = True

def new(self):

# start a new game

self.snake = Snake()

self.run()

def run(self):

# Game Loop

self.playing = True

while self.playing:

self.clock.tick(FPS)

self.events()

self.draw()

self.animate()

self.update()

def update(self):

# Game Loop - Update

pygame.display.update()

def events(self):

# Game Loop - events

for event in pygame.event.get():

# check for closing window

if event.type == pygame.QUIT:

if self.playing:

self.playing = False

self.running = False

def draw(self):

# Game Loop - draw

self.screen.fill((255, 255, 255))

self.snake.draw(self.screen)

def animate(self):

self.snake.animate()

game = Game()

while game.running:

game.new()

pygame.quit()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值