How to leave an image-based trail behind an entity as it moves in Pygame

I'm currently working on a Pygame project. I'm actually working on building a tank game, based on space invaders. The issue is that whenever my tank moves left or right, I want him to leave a certain trail.

The trail is an image of an actual tank trail, and I'd like to keep displaying that image after he moves left, right, down or up, exactly like he's leaving a trail.

I won't post my code since I just need general instructions on this topic, not a specific code clarification or something else.

Here's the trail image:

Upvotes: -1

Views: 61

Answers (1)

Glenn Mackintosh
Glenn Mackintosh

Reputation: 2790

You would have to create an image for the tread marks and then load it using transparency/alpha. Then as you drive you would need to add those to a list with positions trailing the tank as it drove. You would need to keep the entire list of the trail and keep drawing it onto the background as you redraw the screen.

One thing to keep in mind is that if the tank drives back over them, you will not want them visible over the tank, so you will need to layers or just make sure that the tank is drawn last.

Upvotes: 1

Related Questions