Quantcast
Channel: Forum Pasja Informatyki - Najnowsze pytania bez odpowiedzi
Viewing all articles
Browse latest Browse all 21942

wczytywanie mapy c++ SFML

$
0
0
Deklaracja mapy z pliku Level.h
    sf::Vector2i **map=new sf::Vector2i*[100];


#include "Level.h"

void Level::wczytaj_mape(sf::RenderWindow &window)
{
	ifstream openfile("map2.txt");

	
	if (openfile.is_open())
	{
		string tilelocation;
		openfile >> tilelocation;
		map_texture.loadFromFile(tilelocation);//nazwa obrazka z jakiego wczytac tekstury mapy

		tiles.setTexture(map_texture);
		while (!openfile.eof())
		{

			

			map[loadcounter.x] = new sf::Vector2i[25];
			string str;
			openfile >> str;
			char x = str[0], y = str[2];
			if (!isdigit(x) || !isdigit(y))
			{
				
				map[loadcounter.x][loadcounter.y] = sf::Vector2i(-1, -1);
			}
			else
			{
			//	map[loadcounter.x] = new sf::Vector2i[100];
				map[loadcounter.x][loadcounter.y] = sf::Vector2i(x - '0', y - '0');

				/*if (map[loadcounter.x][loadcounter.y] == sf::Vector2i(1, 0))
				{
					cout << "loadcounter.x =   "<< loadcounter.x << "loadcounter.y =   "<< loadcounter.y << endl;
				}*/
			}



			if (l <= 1500)
			{
				std::cout << map[loadcounter.x][loadcounter.y].x<< ","<< map[loadcounter.x][loadcounter.y].y << "";
				l++;

				//std::cout << l % 25<<std::endl;
				if (l % 25 == 0)
				{
					std::cout << std::endl;
				}
			}




			if (openfile.peek() == '\n')//koniec wierszy x
			{
				loadcounter.x = 0;
				loadcounter.y++;
			}
			else
			{
				loadcounter.x++;
			}


			
		}

	}
	else
	{
		cout << "nie wczytalo mapy"<< endl;
	}

}
	//sf::Vector2i map[100][100];
void Level::pokaz_mape(sf::RenderWindow &window)
	{
		for (int i = 0; i < loadcounter.x; i++)
		{
			for (int j = 0; j <= loadcounter.y; j++)
			{
				if (map[i][j].x != -1 && map[i][j].y != -1)
				{
					tiles.setPosition(i * 32, j * 32);
					tiles.setTextureRect(sf::IntRect(map[i][j].x * 32, map[i][j].y * 32, 32, 32));
					if(k<=1500)
					{
						std::cout << map[i][j].x << ","<< map[i][j].y<<""; 
						k++;
						
						//std::cout << l % 25<<std::endl;
						if (k % 25==0)
						{
							std::cout << std::endl;
						}
					}
					window.draw(tiles);

				}
			}

		}

	}

 

 

Dlaczego nie rysuje takiej mapy jak wczytana ?

Wszystko działa jeśli nie użyje dynamicznej alokacji tablicy ale po zmianie na dynamiczną nagle niektóre kafelki sie nie wczytują
Co moze być przyczyną ?

Plik z mapą wygląda tak:

tile.png
1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1
1,1 0,0 1,1 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 1,1
1,1 0,0 0,0 1,1 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 1,1
1,1 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 1,1
1,1 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 1,1
1,1 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 1,1
1,1 0,0 0,0 0,0 0,0 0,0 1,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 1,1
1,1 0,0 0,0 0,0 0,0 0,0 1,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 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0,0 0,0 1,1
1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1


Viewing all articles
Browse latest Browse all 21942

Trending Articles


TRX Antek AVT - 2310 ver 2,0


Автовишка HAULOTTE HA 16 SPX


POTANIACZ


Zrób Sam - rocznik 1985 [PDF] [PL]


Maxgear opinie


BMW E61 2.5d błąd 43E2 - klapa gasząca a DPF


Eveline ➤ Matowe pomadki Velvet Matt Lipstick 500, 506, 5007


Auta / Cars (2006) PLDUB.BRRip.480p.XviD.AC3-LTN / DUBBING PL


Peugeot 508 problem z elektroniką


AŚ Jelenia Góra