In case of tile based sprites printed from a matrix, if you have fixed size tiles, you can know exactly where to begin and where to end printing.
Take the left border X position of your camera and divide by the tile size to get the X index of the first tile to print on the matrix. Divide the X position of your right border by the tile size and add 1 to make sure it goes past the screen, and you have the last X index you are going to print.
Same goes for Y.
Then you have just to iterate on these positions and print them.
Thanks for the reply! I organized my blocks into testBlocks
- [y] now, and I assumed that this loop would iterate through them:
std::map<int, std::map<int, sf::Sprite> > testBlocks;
...
for (int bx = CameraView.Left; bx < CameraView.Width; bx += 32)
{
for (int by = CameraView.Top; by < CameraView.Height; by += 36)
{
App.Draw(testBlocks[bx][by]);
}
}
The actual tile size is 16x18, however they're both scaled by a ratio of 2. I've also tried
bx++;
by++;
As well as
bx += 16;
by += 18;
Initially I assumed the application would crash if I attempted to access a nonexistent index, but that doesn't seem to the the case.
I assume that I'm referring to nonexistent indexes in my std::map, but I'm not sure what I could do to refer to the appropriate ones.