Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎲 GameMaker

What'w wrong with my code?

Started by Chocolate Jun 7, 2010 at 7:15 PM 0 replies 750+ views
Original Post
Chocolate
Chocolate
Here it is:

#include <allegro.h>int main(){		    allegro_init();    install_keyboard();    set_color_depth(32);	set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);   //startup		BITMAP *buffer = NULL;	buffer = create_bitmap(640,480);    BITMAP *noobtown = NULL;	noobtown = load_bitmap("noobtown.bmp", NULL);         //towwn and buffer	blit(noobtown, buffer, 0,0,0,0,640,480);		BITMAP *sprite = NULL;	sprite = load_bitmap("sprite.bmp", NULL);	masked_blit(sprite, buffer, 0,0,0,0,0,0);			int sprite_x = 0;	int sprite_y = 0;                     //coords		 draw_sprite(buffer, sprite, sprite_x, sprite_y); blit(buffer, screen, 0,0,0,0,640,480);  	while(!key[KEY_ESC]){	if(key[KEY_RIGHT])                   //moving{    sprite_x ++;   } else if(key[KEY_LEFT])  {    sprite_x --;  }else if(key[KEY_UP])  {   sprite_y --;     } else if(key[KEY_DOWN]) {    sprite_y ++;   }	 draw_sprite(buffer, sprite, sprite_x, sprite_y); blit(buffer, screen, 0,0,0,0,640,480); clear_bitmap(buffer); 	}       return 0;     }END_OF_MAIN(); 



What happens is the background flashes once then the whole screen turns black except for the sprite, which moves around fine. I need to keep the background though!(Background is noobtown)
ExcessNeo
ExcessNeo
In your game loop you only draw the sprite. You need to also draw the background aswell which explains why it flashes once then disappears.

Topic Locked

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

Sign in to reply to this topic.