frage zum ifstream
-
hab eine quellcode gefunden verstehen aber eine funktion nicht
http://lazyfoo.net/SDL_tutorials/lesson29/index.phpbool set_tiles( Tile *tiles[] ) { //The tile offsets int x = 0, y = 0; //Open the map std::ifstream map( "lazy.map" ); //If the map couldn't be loaded if( map == NULL ) { return false; } //Initialize the tiles for( int t = 0; t < TOTAL_TILES; t++ ) { //Determines what kind of tile will be made int tileType = -1; //Read tile from map file map >> tileType; //If the was a problem in reading the map if( map.fail() == true ) { //Stop loading map map.close(); return false; } //If the number is a valid tile number if( ( tileType >= 0 ) && ( tileType < TILE_SPRITES ) ) { tiles[ t ] = new Tile( x, y, tileType ); } //If we don't recognize the tile type else { //Stop loading map map.close(); return false; } //Move to next tile spot x += TILE_WIDTH; //If we've gone too far if( x >= LEVEL_WIDTH ) { //Move back x = 0; //Move to the next row y += TILE_HEIGHT; } } //Close the file map.close(); //If the map was loaded fine return true; }wie werden den die tiletypen gesetzt in dieser funktion
denn die map datei enthält viele zahlen(als txt datei) und das ganze würd zu einen int(tileType) übertragenoder sehe ich das falsch
aber bei
for( int t = 0; t < TOTAL_TILES; t++ ){
......
.....
tiles[ t ] = new Tile( x, y, tileType );
...
..
}
würd nur eine zahl übertragen (unzwar die erste zahl in der map datei,und dann die zweite..usw)wie funktionirt das jetzt
-
Die x- und y-Koordinaten der Teile werden von 0 an hochgezählt, den zugehörigen Teil-Typ liest du in Zeile 22 aus (ja, da steht nur eine Zahl in der Datei - die einzelnen Werte werden zeilenweise den Tile's zugeordnet.