Need help revolving a 2D array
Posted
by
Brett
on Game Development
See other posts from Game Development
or by Brett
Published on 2012-10-26T14:30:07Z
Indexed on
2012/10/26
17:21 UTC
Read the original article
Hit count: 522
xna-4.0
Pretty much all I'm trying to do is revolve my 2D Array by its container. I'm using this array for a background and I seem to be having problems with it revolving.
public class TileTransformer : GridConstants
{
public Tile[,] Tiles;
ContentManager Content;
public TileTransformer(ContentManager content)
{
Content = content;
}
public Tile[,] Wraping(Tile[,] tiles,Point shift)
{
Tiles = tiles;
for (int x = shift.X; x < 0; x++)//Left shift
{
for (int X = 0; X < GridWidth; X++)
{
for (int Y = 0; Y < GridHeight; Y++)
{
if (X + 1 >GridWidth-1)
{
Tiles[0, Y].Container =tiles[X, Y].Container;
}
else
{
Tiles[X+1, Y].Container =tiles[X, Y].Container;
}
}
}
}
for (int x = shift.X; x > 0; x--)//right shift
{
for (int X = 0; X < GridWidth; X++)
{
for (int Y = 0; Y< GridHeight; Y++)
{
if (X-1==-1)
{
Tiles[GridWidth-1, Y].Container =tiles[0, Y].Container;
}
else
{
Tiles[X - 1, Y].Container =tiles[X, Y].Container;
}
}
}
}
for (int y = shift.Y; y > 0; y--)//shift up
{
for (int X = 0; X < GridWidth; X++)
{
for (int Y = 0; Y < GridHeight; Y++)
{
if (Y - 1 == -1)
{
Tiles[X, GridHeight-1].Container = tiles[X, Y].Container;
}
else
{
Tiles[X, Y - 1].Container = tiles[X, Y].Container;
}
}
}
}
for (int y = shift.Y; y < 0; y++)//shift down
{
for (int X = 0; X < GridWidth; X++)
{
for (int Y = 0; Y < GridHeight; Y++)
{
if (Y + 1 == GridHeight)
{
Tiles[X, 0].Container = tiles[X, Y].Container;
}
else
{
Tiles[X, Y + 1].Container = tiles[X, Y].Container;
}
}
}
}
return Tiles;
}
Now the Problems that I'm having is either when I shift up or left it seems the whole array is cleared back to the default state. Also when I'm revolving the array it appears to stretch it upon the sides of the screen that it is shifting towards.
© Game Development or respective owner