Hi, i want to make a map editor for some game(not mine)
So it uses some files contains paths of textures the game loads it and draw it as a background
I did that too but now i want convert the texture to list of tiles
I mean the tiles inside the texture
Thats my full code
public void CameraMoved()
{
foreach (LoadedTexture t in Textures)
{
t.Texture.Dispose();
}
Textures.Clear();
Textures.Capacity = 0;
int XCoordsToShow = (int)Math.Min(RenderWidth / map.PPuzzle.TileSize/*At the most 256 and some maps use 128*/ + 1, map.PPuzzle.Size.Width);
int YCoordsToShow = (int)Math.Min(RenderHeight / map.PPuzzle.TileSize + 1, map.PPuzzle.Size.Height);
int fpx = Camera.X / map.PPuzzle.TileSize;
int fpy = Camera.Y / map.PPuzzle.TileSize;
if (bfr != null)
bfr.Dispose();
int numberoftiles = (RenderWidth / TileWidth + (RenderWidth % TileWidth)) * (RenderHeight / TileHeight + (RenderWidth % TileHeight));
bfr = new VertexBuffer(renderMgr.Device, numberoftiles * 20, Usage.None, VertexFormat.PositionRhw | VertexFormat.Diffuse, Pool.Default);
st = bfr.Lock(0, 0, LockFlags.None);
primitivecount = 0;
for (int px = 0; px < XCoordsToShow; px++)
{
for (int py = 0; py < YCoordsToShow; py++)
{
int drawX = px;
int drawY = py;
drawX *= map.PPuzzle.TileSize;
drawY *= map.PPuzzle.TileSize;
int pzlindex = map.PPuzzle.Entries[px + fpx, py + fpy];
string dds = Static.GetANI(Static.ConquerPath + "\\" + map.PPuzzle.ANIPath,
pzlindex)[0];
LoadedTexture t = new LoadedTexture();
t.Texture = Helper.LoadTexture(renderMgr.Device, dds);/*256X256 DDS File*/
t.X = drawX;
t.Y = drawY;
Textures.Add(t);
#region TilesInside
for (int x = 0; x < map.PPuzzle.TileSize/TileWidth; x++)
{
for (int y = 0; y < map.PPuzzle.TileSize/TileHeight; y ++)
{
/*The problem in this 4 numbers
* I know its wrong way but i tried other ways and?!
*/
int mapx = x + ((px + fpx)/*Current Puzzle*/+ TileWidth);
int mapy = y + ((py + fpy)/*Current Puzzle*/+ TileHeight);
int drawx = x + drawX;
int drawy = y + drawY;
byte[] b = new byte[] { 0/*Blue*/, 0/*Green*/, 255/*Red*/ , 0/*useless*/ };
if (map.IsValid((ushort)mapx, (ushort)mapy))
{
b = new byte[] { 0/*Blue*/, 255/*Green*/, 0/*Red*/ , 0/*useless*/ };
}
int bgr = BitConverter.ToInt32(b, 0);
st.WriteRange(Helper.GetDiamond(drawx, drawy, TileWidth, TileHeight, bgr));
primitivecount += 4;
}
}
#endregion
}
}
bfr.Unlock();
}
the problem is exactly here :
int mapx = x + ((px + fpx)/*Current Puzzle*/+ TileWidth);
int mapy = y + ((py + fpy)/*Current Puzzle*/+ TileHeight);
int drawx = x + drawX;
int drawy = y + drawY;
what i want to see(from other viewer) :
what i'm seeing :
What i want to know is how can i calculate (MapX,MapY) , (ScreenX,ScreenY (I think that will be easier if i knew the map coordinates )) << i feel like i'm programming now xD