Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python赢得了';不能将rect识别为属性_Python_Attributes_Pygame - Fatal编程技术网

python赢得了';不能将rect识别为属性

python赢得了';不能将rect识别为属性,python,attributes,pygame,Python,Attributes,Pygame,我目前正在制作一个2D platformer游戏,在pygame中按程序生成关卡,但是我收到以下错误消息,阻止我继续: Traceback (most recent call last): File "C:\Users\Win10\Desktop\SCV v3.2.py", line 63, in <module> main() #calls the main function File "C:\Users\Win10\Desktop\SCV v3.2.py", li

我目前正在制作一个2D platformer游戏,在pygame中按程序生成关卡,但是我收到以下错误消息,阻止我继续:

Traceback (most recent call last):
  File "C:\Users\Win10\Desktop\SCV v3.2.py", line 63, in <module>
    main() #calls the main function
  File "C:\Users\Win10\Desktop\SCV v3.2.py", line 36, in main
    block_object = block_class(0, 5)
  File "C:\Users\Win10\Desktop\SCV v3.2.py", line 29, in __init__
    self.image.Rect = (32, 32)  #block is 32*32 pixels large
AttributeError: 'pygame.Surface' object has no attribute 'Rect'
您可以在此处设置曲面宽度和高度。曲面中没有rect attr。
A
pygame.Surface
对象没有
Rect
属性。你为什么要定一个呢?
import pygame          #imports pygame
import time            #imports the timer so I can use the tick function to make game 60 fps
import sys          #imports system
from pygame import *   #imports all pygame files

win_height = 500  #height of the window is 500 pixles
win_width = 500   #width of the window is 500 pixels 
red = (255, 0, 0) #makes red a preset colour using rgb
green = (0, 255, 0)  #makes green a preset colour using rgb

display = (win_height, win_width)   #creates the windown as 500*500 pixels

depth = 32    #prevents infinate recursion

timer = pygame.time.Clock()  #creates a timer

flags = 0  #I don't really know what this does, however I have seen in many places it being used, therefore I assumed that it was important

screen = pygame.display.set_mode(display, depth, flags)  #loads up a pygame window

class entity(pygame.sprite.Sprite):    #makes player a sprite
    def __init__(self):
        pygame.sprite.Sprite.__init__(self) #sets sprite to initiate


class block_class(entity):
    def __init__(self, x, y):
        self.image = Surface((32, 32))
        self.image.rect = (32, 32)  #block is 32*32 pixels large
        self.image.fill(Color ("#FF0400"))  #block is red
        self.image.convert()
        self.rect = Rect(x, y, 32, 32)


def main():  #main game function
    block_object = block_class(0, 5)
    player_object = player_class(0,0)   


    while 1:       #updates the screen so you can see changes like movement
        timer.tick(60)
        player_object.update()
        screen.fill(red)  #makes the screen red(will probably be temporary)
        pygame.display.update()





class player_class(entity):  #defines the player class
    def __init__(self, x, y):  #x is the players x coordinate, y is player y coordinate
        self.xvel = 0  #how fast the player is moving to the left and right
        self.yvel = 0 #how fast the player is moving up and down
        self.image = Surface((32, 32))
        self.image.rect = (32, 32)  #player is 32*32 pixels large
        self.image.fill(Color ("#00FF33"))  #player is green
        self.image.convert()
        self.rect = Rect(x, y, 32, 32)
    def update():
        pass


main() #calls the main function
self.image = Surface((32, 32))