I just learned how to group stuff in pygame but when I try to use it to draw a sprite it says: " ExternalError: TypeError: Cannot read property 'left' of undefined on line 32"
Here is my code:
import pygame from pygame import * screen = pygame.display.set_mode((600, 600)) blocks = pygame.sprite.Group() class Block(): def __init__(self, x, y, w, h, typ): super().__init__() self.x = x self.y = y self.w = w self.h = h self.typ = typ def draw(self): pygame.draw.rect(screen, (0, 0, 0), (self.x, self.y, self.w, self.h)) class Player(): def __init__(self, x, y): super().__init__() self.x = x self.y = y self.accX = 0 self.accY = 0 def draw(self): pygame.draw.rect(screen, (0, 0, 0), (self.x, self.y, 20, 20)) player = Player(0, 0) while True: Blocks = Block(0, 0, 100, 50, 1) blocks.add(Blocks) blocks.draw(screen) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() pygame.display.update()
https://stackoverflow.com/questions/66961536/how-to-draw-shapes-using-the-grouping-thing April 06, 2021 at 09:08AM
没有评论:
发表评论