As @101 mentioned in a comment, sprite
is a pygame
[sub] module, but is not itself a Python class
. To do what you want, you'll need to derive your subclass from the Sprite
class that module defines. This means using something along the lines below. (There's also an example in the pygame
documentation of a slightly different way of creating a Sprite
subclass which you should probably take a look at.)
Note also that class names should have their initial letter Capitalized according to Naming Conventions section of the PEP 8 - Style Guide for Python Code, so I've fixed that as well.
from pygame.sprite import Sprite
class Sp(Sprite):
pass
To answer the other part of your question where you're trying to use sp.Group()
. The problem is what you're trying to do is just plain incorrect. Group
is a separate "container" class that's also defined in the pygame.sprite
module. It's primary purpose to group a bunch of Sprite
class instances. It should be able to handle your Sprite
subclass just fine. Below is more code showing how that can be done:
from pygame.sprite import Group, Sprite
class Sp(Sprite):
pass
# Create a Group container instance and put some Sp class instances in it.
mygroup = Group()
sp1 = Sp() # Create first instance of subclass.
mygroup.add(sp1) # Put it in the Group (NOT via sp1.Group())
sp2 = Sp() # Create another instance of subclass.
mygroup.add(sp2) # Put it into the Group, too.