my code is copied below
class Bullet(pygame.sprite.Sprite):
def __init__(self ,x, y, direction):
pygame.sprite.Sprite.__init__(self)
self.speed = 10
self.image = bullet_img
self.hitbox = self.image.get_rect()
self.hitbox.center = (x,y)
self.direction = direction
def update(self):
#move bullet
self.hitbox.x +=(self.direction*self.speed)
#check if bullet off screen
if self.hitbox.right <0 or self.hitbox.left>SCREEN_WIDTH:
self.kill()
traceback:
File "C:\Users\bobby\AppData\Local\Programs\Python\Python311\Lib\site-packages\pygame\sprite.py", line 551, in draw zip(sprites, surface.blits((spr.image, spr.rect) for spr in sprites)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\bobby\AppData\Local\Programs\Python\Python311\Lib\site-packages\pygame\sprite.py", line 551, in <genexpr> zip(sprites, surface.blits((spr.image, spr.rect) for spr in sprites)) ^^^^^^^^ AttributeError: 'Bullet' object has no attribute 'rect'
attempting to spawn in a bullet however the get_rect function from pygame to produce its hitbox is not working