|
|
| Loading image from .dat file |
|
moodle
Member #11,648
January 2010
|
So, I'm pretty much stuck with this for quite a while now I'm trying to put all my images in a .dat file but grabber doesn't work in Vista, so I got dat for linux and put all the images in a .dat file using linux. The only problem is that I can't get the images to be loaded in the game. It compiles fine, but the images don't show up on the screen. 1DATAFILE *data;
2BITMAP *background;
3packfile_password("password");
4data = load_datafile("dat1.dat");
5packfile_password(NULL);
6background = (BITMAP*) data[BACKGROUND_BMP].dat
Is something wrong with my code? |
|
William Labbett
Member #4,486
March 2004
|
I've a feeling it would help if you showed more code. Also, there should be a ';' on the last statement but I guess you cut and pasted a bit inaccurately missing the last character. I don't think anyone can diagnose your problem from the code you posted because it all seems okay.
|
|
moodle
Member #11,648
January 2010
|
What else would you like to see? I've attached my main file just in case |
|
William Labbett
Member #4,486
March 2004
|
Sorry moodle. I can tell by your code that you know more about it all than me. You need someone else to help. Just wondered if you'd called allegro_init() before loading the datafile. EDIT : something tells me you're problem is because you made the dat file on linux though.
|
|
OnlineCop
Member #7,919
October 2006
|
This is what I've seen some do: 1void init_players(void)
2{
3 DATAFILE *pb;
4 unsigned int i, j;
5
6 pb = load_datafile_object(PCX_DATAFILE, "USCHRS_PCX");
7
8 if (!pb)
9 {
10 printf("Could not load character graphics!");
11 exit(0);
12 }
13
14 for (i = 0; i < MAX_CHARACTERS; i++)
15 {
16 for (j = 0; j < MAX_FRAMES_PER_CHAR; j++)
17 {
18 blit((BITMAP *) pb->dat, frames[i][j], j * ENTITY_W, i * ENTITY_H, 0, 0, ENTITY_W, ENTITY_H);
19 }
20 }
21
22 unload_datafile_object(pb);
23}
It may not be the way your dat file is set up, but it may help.
|
|
moodle
Member #11,648
January 2010
|
@OnlineCop I mean, my problem doesn't seem to be with loading the file. I've added an if statement to print something if I wasn't able to load it, and it didn't print anything. So I have no idea of wtf is going on.. |
|
OnlineCop
Member #7,919
October 2006
|
I was more referring to line 18...
|
|
William Labbett
Member #4,486
March 2004
|
|
OnlineCop
Member #7,919
October 2006
|
I dunno; you only sent main.cpp, and we need 1#include "common.h"
2#include "includes.h"
3#include "gamebasics.h"
4#include "dat.h"
|
|
moodle
Member #11,648
January 2010
|
@William @OnlineCop EDIT: Ok, nevermind it...I guess the problem was when I created the .dat file in linux. Thanks anyways |
|
William Labbett
Member #4,486
March 2004
|
What about if you try :- ...right after you load it. Again I'm probably underestimating your abilities but I wondered if there might be some other error in your code which would mean the bitmap's getting drawn somewhere off-screen.
|
|
moodle
Member #11,648
January 2010
|
@William Now, since my images will be loaded by many different classes in different files, I was trying to put my DATAFILE as a global variable, but my compiler is complaining(probably about the packfile_password()- not 100% sure about this. I declared my DATAFILE as an extern variable on my gamebasics.h file, and I'm doing this in the .cpp: 1packfile_password("password");
2DATAFILE* data = load_datafile("data.dat");
3packfile_password(NULL);
And the error I get is: error: This error pops up on the 2 lines where I'm using packfile_password..Any clues? |
|
OnlineCop
Member #7,919
October 2006
|
If you want DATAFILE* data to be global, shouldn't this work fine? DATAFILE* data = NULL; ... void that_function(void) { ... packfile_password("password"); data = load_datafile("data.dat"); ... }
|
|
moodle
Member #11,648
January 2010
|
Yes, it should Some of the images appear just fine, and others are completely screwed up. And now the game stops working all of a sudden.. |
|
cwl157
Member #11,639
January 2010
|
If the grabber won't work you can use the dat.exe command line tool to add files to a dat file. Also, i ran into the same problem. Is this a C program or C++ program? I just wrote a game in C and put all my images into a dat file and ran into the same thing. To fix it i had to load all the images for all the sprites before i setup the sprite data like x, y, etc. This is assuming the BITMAP images for the sprites are separate from the other sprite data. It isn't as organized but its the only thing i found to fix it. If you are using C like i did, i used malloc to create the sprites, my only guess is somehow calling this before loading an image was somehow messing it up. So by loading all the images first and then using malloc to create the sprites fixed it. |
|
LennyLen
Member #5,313
December 2004
|
moodle said: I'm trying to put all my images in a .dat file but grabber doesn't work in Vista Grabber runs just fine with Vista.
|
|
|