Drawing on a Texture

Hi folks, me again.

Scenario, 2D top down game.

While messing about with something really abstract, (just learning stuff) I wondered about tracing the movement of a sprite. Imagine a car game where you drift around a corner and leave some lovely black lines, but you can see the skid marks disparaging after time as you drive around. In this case the author is obviously drawing sprites, or at least a list of textures on top of the background, and when the lifetime of the object is reached it’s removed.

This made me think, why not draw the ‘skid marks’ on the background texture? A bonus would be, if I make subtle changes to the colours of pixels the effect could build up over time.

So I guess there are two questions.

  1. Can I write/change the colour of pixels of a content.load texture during run time.
  2. If possible, is this a heavy overhead?

Tired and signing off.

For this case you want to use a render target you draw into and not clear at the end of the frame. Problem though is that if your camera moves a lot, your render target won’t be big enough to cover a big map. Depending on the size of your game world, you most likely will need to stick to drawing sprites for saved locations where your car drove along, or create a grid of smaller render targets if the world is not too big to have your RAM explode.

Assuming in this case the game world is no bigger than the view window and the background.png is also no larger, I would draw the background texture and the additional pixel information to a separate render target?

I get the principal, could you point me towards a good tutorial explaining this process?

I’m guessing I would then need a copy of the unaltered background texture to use for collision testing?