Witam, gdy kompilowałem program, wystąpił mi pewien błąd i nie wiem jak go rozwiązać. Kompiluje na platformie x64
Kod w którym występuje błąd:
int id = Convert.ToInt32(items[x]);
Błąd:
System.FormatException: „Nieprawidłowy format ciągu wejściowego.”
Cały kod:
using SFML.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pifpaf
{
class mapa
{
Sprite[,] tiles;
int MapWidth = 100;
int MapHeight = 100;
public mapa()
{
int TitleMapWidth = 21;
int TitleMapHeight = 23;
int TileSize = 32;
Texture texture = new Texture("Maps/sheet.png");
Sprite[] titlemap = new Sprite[TitleMapWidth * TitleMapHeight];
for (int y = 0; y < TitleMapHeight; y++)
{
for(int x = 0; x < TitleMapWidth; x++)
{
IntRect rect = new IntRect(x * TileSize, y * TileSize, TileSize, TileSize);
titlemap[(y * TitleMapWidth) + x] = new Sprite(texture, rect);
}
}
tiles = new Sprite[MapWidth, MapHeight];
StreamReader reader = new StreamReader("Maps/mapa2.tmx");
for(int y = 0; y < MapHeight; y++)
{
string line = reader.ReadLine();
string[] items = line.Split(',');
for (int x = 0; x < MapWidth; x++)
{
int id = Convert.ToInt32(items[x]);
tiles[x,y] = new Sprite(titlemap[id]);
tiles[x, y].Position = new SFML.System.Vector2f(TileSize * x, TileSize * y);
}
}
reader.Close();
}
public void Draw(RenderWindow window)
{
for(int y = 0; y < MapHeight; y++)
{
for(int x = 0; x < MapWidth; x++)
{
window.Draw(tiles[x, y]);
}
}
}
}
}