I made a class 'Level', public of class 'Buffer', with a SetLevel function that mask blits the "walls" of the game to the buffer. Well, it actually doesn't, the sprite is not visible in the window. I tried then mask bliting it in the main function by making functions that return the buffer and the 'wall' variables ... and it worked.
Now I'm just confused. The masked_blit() can't blit from inside a class? The blit function can.
Here are the classes:
- Code: Select all
// CreateBuffer.h
class CreateBuffer {
protected:
BITMAP* Buffer;
public:
CreateBuffer();
~CreateBuffer();
BITMAP* GetBuffer() { return Buffer; }
void BlitBuffer();
void ClearBuffer();
};
CreateBuffer::CreateBuffer() {
Buffer = create_bitmap( 800, 600 );
}
CreateBuffer::~CreateBuffer() {
destroy_bitmap( Buffer );
}
void CreateBuffer::BlitBuffer() {
blit( Buffer, screen, 0, 0, 0, 0, 800, 600 );
}
void CreateBuffer::ClearBuffer() {
clear_bitmap( Buffer );
}
- Code: Select all
// Level.h
class Level: public CreateBuffer {
private:
BITMAP* Wall;
public:
Level();
void SetLevel();
BITMAP* GetWall() { return Wall; }
~Level();
};
Level::Level() {
Wall = load_bitmap( "data/castle.bmp", NULL );
}
void Level::SetLevel() {
masked_blit ( Wall, Buffer, 0, 0, 0, 0, 96, 28 );
}
Level::~Level() {
destroy_bitmap( Wall );
}
And here is the main function that works:
- Code: Select all
#include "Library.h"
int main() {
AllegroSetup cInitialized(1);
CreateBuffer cBuffer;
Level cLevel;
masked_blit( cLevel.GetWall(), cBuffer.GetBuffer(), 0, 0, 0, 0, 800, 600 );
cBuffer.BlitBuffer();
readkey();
return 0;
}
END_OF_MAIN();
But when I try to use the SetLevel function inside of the Level class I get no sprite on the buffer
- Code: Select all
#include "Library.h"
int main() {
AllegroSetup cInitialized(1);
CreateBuffer cBuffer;
Level cLevel;
cLevel.SetLevel();
cBuffer.BlitBuffer();
readkey();
return 0;
}
END_OF_MAIN();
All my header files are included in a 'library' header which I include in all .cpp files. The AllegroSetup class just initializes allegro.
I did, redid, rerererereredid it all, tried different ways to do it, and that's the single think that won't work, mask blitting from inside a class!
I read the docs' about masked_blit and there's nothing about 'not working in a class', it kind of sounds unreal, why wouldn't it work in a class ? :\
Just give me a straight answer, even if it's 'YOU ARE IDIOT !". Thanks. :-<
Side note: I used Moosader's sprites for this project, thank you.
