Hello all,
I’m sorry if the topic is a little vague as I’m not sure exactly how to word it. I only post on forums maybe twice a year, haha!
Anyway, I have a problem. I know what I want to happen, but I dunno how to approach it with my current set up and I’m pretty sure I’ve searched out every possible topic on it that I can think of.
I’m working on a “world map” of sorts and am using a sprite sheet with each tile a 64 x 64 image.
I’m loading the rectangles into a dictionary and calling them based on a number found in the int[,] array, or grid if you will.
I draw the map and all is well and perfect, but then, like any good world map, I want it to wrap from all sides, or repeat to be able to “circle the world” so to speak. I cannot for the life of me fin any documentation on this. All that I find is just what I’ve already accomplished.
I’ll show some code here to show HOW I’ve drawn the tiles. It’s better than my trying to type it haha.
Here’s the Draw
spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null, null, transformMatrix: camera.GetViewMatrix());
int spriteX = 0;
int spriteY = 0;
Rectangle texture;
for (int x = 0; x < worldLayout.GetLength(0); x++)
{
for (int y = 0; y < worldLayout.GetLength(1); y++)
{
int tileNumber = worldLayout[x,y];
texture = worldMap[tileNumber];
spriteBatch.Draw(worldMapSpriteSheet, new Vector2(spriteX, spriteY), texture, Color.White, 0, new Vector2(0, 0), 1.0f, SpriteEffects.None, 0);
spriteX += texture.Width;
}
spriteX = 0;
spriteY += 64;
}
spriteBatch.End();
Here’s the result and what I’d LIKE to happen
Don’t mind the numbers on the images, that’s my debug. The numbers match the dictionary entry to ensure I have the right tile is all.
As it is, I’m using the camera library built into .Extended and move the output around based on that matrix. Eventually I’ll have that camera snapped to a character, but for now, I’m focused on getting this small island to repeat to prepare for a much much bigger world!
With this set up, I understand that each tile is it’s own rectangle which is where I’m hung. How can I wrap this around with all of these rectangles and what will that do to the performance? Is there a better way to approach this?
Does any of this make sense?
Thanks for any feedback!