I want to create a sprite in Python. Also, how do you clone/delete sprites? Thanks. I’m trying to make a Cell Machine mod.
When you refer to
Sprite are you talking about a characters or objects on the screen of a game?
If so, Then you want to use the
pygame module. Then you can create a
Sprite class like so:
import pygame # Object class class Sprite(pygame.sprite.Sprite): def __init__(self, color, height, width): pass
Then you can “clone” as many as you lie from this class blueprint. If you want to delete the Sprite, add a
__del__ magic method to the class:
import pygame # Object class class Sprite(pygame.sprite.Sprite): def __init__(self, color, height, width): pass def __del__(self): print("Deleted...")
Then you could delete the object instance like so:
seraph = Sprite('black & red', 77, 6) del seraph
Does that answer your question?
Hmm. I appreciate your help but it’s not working. It shows an error. Do I have to, like, download pygame?
I apologize for not fully explaining myself. Yes, you will need to install the
pygame module to run this code. I was showing you an example of how to develop a
You mentioned you’re developing a “Cell Machine” mod, correct? If you feel comfortable posting your code I might be able to guide your process. But this is how you build a basic Sprite. Please let me know if you have any other questions, I’ll be glad to help!
Basically, Cell Machine is a sandbox with bunch of squares. The blue one moves, the green one clones the square behind it, the orange and turquoise rotate, the hashtag does nothing, the grey just stops everything that comes to it, the purple deletes everything that comes to it, and the red is just a purple except when it deletes something it also deletes itself.
There are also remakes of it with like 500 more squares lol