Skip to main content
gamedev.net
🔒 Locked

tile loading, arrg!!

Started by jt_845s Dec 1, 2000 at 3:00 PM 7 replies 600+ views
Original Post
jt_845s
jt_845s
ok. i''m making a *simple* tiled map editor. i''m using pure win32 for the code (please don''t lecture me on using mfc or vb). here''s my problem: in my tiles sub-directory, i have all of my bitmapped tiles, and a file - tiles.txt - that contains the filenames of the tiles. but my tile loading function will only load the last tile specified in the file! code:
  
HBITMAP bmp[256];
int     numBitmaps = 0;
int LoadTiles(void)
{
	FILE* f;          // File handle to open

	char  fname[256]; // Current file name

	int   i=0;

	// Open the ''tiles.txt'' file for reading

	if ((f = fopen("tiles\\tiles.txt", "r")) == NULL)
		return 0;
	
	// Load the filenames into HBITMAPS

	while (!feof(f)) 
	{
		fgets(fname, 96, f);

		// Load the bitmap 

		bmp[numBitmaps] = (HBITMAP) LoadImage(GetModuleHandle(NULL), fname, IMAGE_BITMAP, 0, 0,
			                            LR_LOADFROMFILE | LR_CREATEDIBSECTION);

		if (bmp[numBitmaps] == NULL)
			Message("Unable to load bitmap %s", (char*)fname);

		numBitmaps++;
	}
	
	fclose(f); // Close the file


	return 1;
}
  
if my ''tiles.txt'' file looks like this: tiles\\ground_001.bmp tiles\\ground_002.bmp the function will only load the ''ground_002.bmp'' file! am i just missing something little here? help would be appreciated. thanks.
  #define ignite_software 1  
[source]#define ignite_software 1[/source]
jt_845s
jt_845s
anybody...?

  #define ignite_software 1  
[source]#define ignite_software 1[/source]
Quantum
Quantum
So is it only loading the last bitmap, or is it starting at the second and loading the rest?
Burning_Ice
Burning_Ice
hmm i don''t see any real error in your code, but try setting a

rewind ( f );

after opening the file and before the while loop, so it positions the file pointer at the beginning and you can at least be sure it starts with the first line in the file

hope that helps
jt_845s
jt_845s
it only loads the last bitmap. and i know the first bitmap int the file is bieng called, i set up a message function to tell me what''s going on. if you want to check out the source, let me know. i''ll email it to you. thanks

  #define ignite_software 1  
[source]#define ignite_software 1[/source]
jt_845s
jt_845s
can no one figure this riddle out???? I tried ALL weekend with no success. I''ll have to try to use another routine, i guess (!!but which one?!?!?!)

  #define ignite_software 1  
[source]#define ignite_software 1[/source]
jt_845s
jt_845s
I FIXED IT!!! The problem was with fgets. I used fscanf, and it worked perfectly. And i meant that only the last filename in the tiles.txt file would be loaded.

  #define ignite_software 1  
[source]#define ignite_software 1[/source]
FordPrefect
FordPrefect
A little late, since you''ve gotten it working, but if you''re curious, the reason it was failing was because fgets was appending a newline to the filename, and the call to fopen was failing because, obviously, the real file name doesn''t have a newline in it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.