Python draw()缺少1个必需的位置参数:';表面';
Python版本:3.4 PyGame?:是 好吧,我正在使用Python和PyGame,并且在youtube上学习教程,因为我是编程新手 我已经尝试过多种方法,比如在参数中添加一个_块,还有我的game_显示,但是它说我的对象块没有被调用的精灵。 我也尝试过多次搜索这个,但我还没有找到任何有用的东西。我相信教程是在Python 2中完成的 块类:Python draw()缺少1个必需的位置参数:';表面';,python,pygame,sprite,Python,Pygame,Sprite,Python版本:3.4 PyGame?:是 好吧,我正在使用Python和PyGame,并且在youtube上学习教程,因为我是编程新手 我已经尝试过多种方法,比如在参数中添加一个_块,还有我的game_显示,但是它说我的对象块没有被调用的精灵。 我也尝试过多次搜索这个,但我还没有找到任何有用的东西。我相信教程是在Python 2中完成的 块类: # Creates a class for our block class Block (pygame.sprite.Sprite): #
# 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)
我的主要游戏循环的一部分:
# 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)
lock\u group=pygame.sprite.group()
我甚至没有注意到,请在下面的答案中标记感谢。