Question

I made a 2D project with a lot of tile sprites, and one player sprite. I'm trying to get the camera to follow the player, and for the most part it's working. However, there's one problem:
If you go to the edge of the map, it scrolls normally, but instead of the black background, it displays copies of the sprites on the edge of the map instead of the background (black). It has the same problem if I leave some squares empty, when I move it displays a copy of the tile that was previously there.

The camera works like this:

  • Select sprites that should be visible
  • Do sprite.visible = 1 for them, and sprite.visible = 0 for all other sprites
  • Set the position sprite.rect of all sprites to coords - offset
  • Update the screen (I use flip(), because the camera moves every turn, so the whole screen has to be updated every turn)

All DirtySprites have dirty = 2.

Does anyone know why it's displaying copies of the sprites on the edge instead of the background?

Help would be appreciated!

Was it helpful?

Solution

Unless you manually clear your screen surface, flip will not change its content.

Thus, if you neglect to draw to a certain location, it will remain the same.

If you want to get rid of this effect, usually called "hall of mirrors", you will have to keep track of what portions of the screen have not been drawn to yet and draw over these yourself.

It may be easier to define background sprites around your map's contours and block your camera from going off too far.

Since you use a "dirty/clean" approach to only redrawing what's changed, you won't have the option to just fill the whole screen surface before you draw your frame, because that would draw over anything that's stayed the same since the last frame.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top