|
c++ Allegro 5 - drawing bitmap region over backgound |
robgordon
Member #16,604
December 2016
|
complete game programming newbie here so please bear with me. I'm trying to learn a bit about 2D game programming by trying to code a Space Invaders clone. I can draw the backgound image (an arcade .bmp with a magenta square, which is where the game would display), but I'm at a loss when trying to draw a spaceship in said square. My code snippets are as follows (all includes are taken care of, since the background is being loaded). Main method: 1ALLEGRO_BITMAP *background = al_load_bitmap("Resources/bkg.bmp");
2
3 al_register_event_source(event_queue, al_get_display_event_source(display));
4 al_register_event_source(event_queue, al_get_timer_event_source(timer));
5 al_register_event_source(event_queue, al_get_keyboard_event_source());
6
7
8 al_set_target_bitmap(al_get_backbuffer(display));
9 al_clear_to_color(al_map_rgb(0,0,0));
10
11Character spaceship("Recursos/ship.bmp" , "Resources/bullet.bmp" , 6 , 12 , 30, 20,
12 300, 530, -6, 3 , "Resources/sound.wav" , "Resources/explosion.wav");
13
14 Character *player;
15 player = &spaceship;
16
17 al_convert_mask_to_alpha(background, al_map_rgb(255, 0 , 255));
18
19 al_draw_bitmap(background,0,0,0);
20 spaceship.draw(player, background);
21 al_flip_display();
Game Character class: 1void Character::draw(Character* character, ALLEGRO_BITMAP* bkg){
2 al_convert_mask_to_alpha(character->characterImg, al_map_rgb(255, 0 , 255));
3 al_set_target_bitmap(bkg);
4
5 //al_draw_bitmap_region(ALLEGRO_BITMAP *bitmap,
6 //float sx, float sy, float sw, float sh, float dx, float dy, int flags)
7
8 al_draw_bitmap_region(character->characterImg, 0, 0, 28, 20, 100, 100, 0);
9 al_flip_display();
10}
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
You're flipping the display twice. That will likely result in a blank or corrupted image displayed on the screen. Only flip the display once per refresh. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|