draw()缺少1个必需的位置参数:'surface'

时间:2015-05-29 22:05:42

标签: python pygame sprite

Python版本: 3.4

PyGame?:

好吧所以我正在使用Python和PyGame以及关于youtube的教程,因为我是编程新手。

我尝试了多种方法,例如在参数中添加a_block以及我的game_display但是它说我的对象Block没有调用sprite的东西。 我也试过多次搜索,但我还没有找到任何有用的东西。我认为教程是在Python 2中完成的。

Block Class:

# Creates a class for our block
class Block (pygame.sprite.Sprite):
    # Creates an object
    def __init__(self,colour = blue,width = 64,height = 64):

        super(Block,self).__init__()

        self.image = pygame.Surface((width,height))
        self.image.fill(colour)
        self.rect = self.image.get_rect()

    def set_position(self,x,y):
        self.rect.x = x
        self.rect.y = y

我的主要游戏循环的一部分:

# Main game loop
if (__name__ == "__main__"):
    # Initilizes all the sub modules inside of pygame.
    pygame.init()

    # Shortens what would be 2 window sizes into 1 variable
    window_size = window_width, window_height = 640,480
    # Takes the window size variable called display_size and makes the window
    game_display = pygame.display.set_mode(window_size)
    # Sets the window/caption name/title
    pygame.display.set_caption("Game")

    # Sets the game FPS(Frames Per Second)
    clock = pygame.time.Clock()
    FPS = 60

    # block sprite group
    block_group = pygame.sprite.Group

    a_block = Block()
    a_block.set_position(window_width/2,window_height/2)

    block_group.add(a_block)

    # Draws the sprite group called block to the game_display
    block_group.draw(game_display)

1 个答案:

答案 0 :(得分:1)

lock_group = pygame.sprite.Group() # instantiate the class to create an object