Skip to content
Advertisement

How can i get the number of an image of a certain sprite in pygame

I randomly share pictures of houses on the screen. Then I drive a car across the screen.When the car hits a house, the image of that house should be replaced with a modified copy of that house. I distribute the images with the following function

JavaScript

I check the collision car with house

JavaScript

…. How do I then get the house number or picture number of the house that collided so that I can replace the picture with a slightly modified copy?

Advertisement

Answer

Store the image number in an attribute of the Sprite class:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement