I'm making my first game of Pygame. I'm going to create groups for making collisions but when I add an object to the group, I get an error in sprite.py (Pygame's Files)
AttributeError: 'pygame.Surface' object has no attribute 'add_internal' Why I get this error?
There is a simplest way to make collisions?
There is my code:
import pygame from pygame.locals import * import sys import os import time width = 950 height = 500 Game = False GameOver = False keyboard = pygame.key.get_pressed()[K_UP] def main(): pygame.init() screen = pygame.display.set_mode((width, height)) pygame.display.set_caption('Flappy Dog') background = pygame.image.load(os.path.join("Images", "Background_00.png")).convert() FlappyDog = pygame.image.load(os.path.join("Images", "Flappy.png")).convert_alpha() Play = pygame.image.load(os.path.join("Images", "Play.png")).convert_alpha() Dog0 = pygame.image.load(os.path.join("Images", "Dog0.png")).convert_alpha() Dog1 = pygame.image.load(os.path.join("Images", "Dog1.png")).convert_alpha() SpikeUp0 = pygame.image.load(os.path.join("Images", "SpikeUp0.png")).convert_alpha() SpikeUp1 = pygame.image.load(os.path.join("Images", "SpikeUp1.png")).convert_alpha() SpikeDown0 = pygame.image.load(os.path.join("Images", "SpikeDown0.png")).convert_alpha() SpikeDown1 = pygame.image.load(os.path.join("Images", "SpikeDown1.png")).convert_alpha() GameOver = pygame.image.load(os.path.join("Images", "Game-Over.png")).convert_alpha() Replay = pygame.image.load(os.path.join("Images", "Replay.png")).convert_alpha() Bone = pygame.image.load(os.path.join("Images", "Bone.png")).convert_alpha() Game = True Dog1_pos_x = 100 Dog1_pos_y = 100 screen.blit(background, (0, 0)) screen.blit(FlappyDog, (0, 0)) screen.blit(Bone, (550, 100)) screen.blit(Play, (600, 350)) screen.blit(Dog0, (5, 240)) bones = pygame.sprite.Group() bones.add(Bone) # <-- Error here Dog = pygame.sprite.Group() Dog.add(Dog1) pygame.display.update() while True: if GameOver == true: screen.blit(background, (0, 0)) screen.blit(GameOver, (20, 50)) if pygame.sprite.gropucollide(Dog, Bones, True, True): Game = False GameOver = True while Game == True: pygame.event.pump() if pygame.key.get_pressed()[K_UP]: for i in range(10): # Up Dog1_pos_y = Dog1_pos_y -1 screen.blit(background, (0, 0)) screen.blit(Dog1, (Dog1_pos_x, Dog1_pos_y)) screen.blit(SpikeDown0, (0, 436)) screen.blit(SpikeUp0, (0, 0)) pygame.display.update() pygame.time.delay(1) else: # Down Dog1_pos_y = Dog1_pos_y +1 screen.blit(background, (0, 0)) screen.blit(Dog1, (Dog1_pos_x, Dog1_pos_y)) screen.blit(SpikeDown0, (0, 436)) screen.blit(SpikeUp0, (0, 0)) pygame.display.update() pygame.time.delay(1) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() pygame.display.update() if __name__ == "__main__": main()
bonesSpikes.add (SpikeDown0)and in a pygame file (Sprite.py) \$\endgroup\$SpikeDown0is aSurface, and you're trying to add it to a group made to containSpriteobjects. Did you follow the linked answer and try something likeSpikeDown0Sprite = pygame.sprite.Sprite()SpikeDown0Sprite.image = SpikeDown0...boneSpikes.add(SpikeDown0Sprite)? \$\endgroup\$