-
hey Vicious i tried this and works really well:
Code:
#include <allegro.h>
int counter;
int x = 300, left = 0, right = 0;
void update_counter()
{
counter++;
}
END_OF_FUNCTION(update_counter);
int main()
{
allegro_init();
install_keyboard();
LOCK_VARIABLE(counter);
LOCK_FUNCTION(update_counter);
install_int_ex( update_counter, BPS_TO_TIMER(60));
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
BITMAP *ship = load_bitmap( "ship.bmp", NULL );
draw_sprite ( screen, ship, x, 300 );
while ( !key[KEY_ESC] )
{
while (counter > 0) {
if (left) x-=5;
if (right) x+=5;
counter--;
}
if ( x < 540 && key[KEY_RIGHT])
right = 1;
else
right = 0;
if ( x > 50 && key[KEY_LEFT])
left = 1;
else
left = 0;
vsync();
clear_to_color (screen, 0);
draw_sprite ( screen, ship, x, 300 );
}
destroy_bitmap(ship);
allegro_exit();
return 0;
}
END_OF_MAIN();
the only problem is that it messes up a tiny bit at the beginning and it leaves a trail once you move the bmp. however, there isn't any flickering at all right after the beginning.
-
yup, if you dont put in the buffer thingy it will leave a trail i think....
it will work better than the clear(screen) or the clear_to_color...
try it?
-
I just tried the vsync() before you blit and it flickers way too much. My above code (well mostly yours actually;) ) works the best so far.
-
does you clear(screen) method leave a trail?
-
replacing clear to color() with clear(screen) doesn't work as well in that example doesn't work as well.
-
how bad was the flicker when it didnt leave a trail?
bad bad?
screenshot?
sorry, ill quit asking these stupid questions when i get to my computer
-
It's bad enough that it would not be acceptable in a game. The trail is not nearly as bad as the flickering. I'm trying some things out right now.
What I've been trying to do is to not blit the bmp but only blit the bmp when the bmp is moved. So if the bmp is not being moved there shouldn't be any flickering. But everytime I try this I mess everything up entirely.
-
have you tried
Code:
if ( keypressed() )
{
//do the vsync(), draw_sprite(), blit....
}
and what kind of trail we talkin bout? you mean like a blur? or an actual trail?
-
yeah i tried that...basically anytime blit is involved there is a lot of flickering.
the trail is just like a blur. it's not all that bad but of course you'd rather have it without a blur.
-
oh, that blur.... yah its just part optical part bright color moving fast against a black background
:rolleyes:
its rally unavoidable if it is what im thinking
-
Oh well then that's awesome, and I'm sure you're right, too.
-
I have a question. If somebody uses your program on their computer and they don't have allegro installed what files will they need? I even had the person get the allegro40.dll file and my program still wouldn't work. he tried both in the folder of the program itself and in the windows/system folder. For some reason it would never work. I'm above 100% positive that it is not because of the program. The program works perfectly fine for me. Are there any other files that person needs in order to execute my program?
-
If you staticly link it, they do not need the files. And it is not the blit creating the flicker, it is the clearing of the screen. Just use two screen buffers. Draw to the back one, then when that is done, flip it to the front one (don't blit it) and it should not flicker.
-
I am downloading the latest version of Allegro, if I can get it working with C++ Builder I am gonna figure out the best way to move sprites without flicker.
-
tech... i used vsync() before that last blit and it did fine until i went up into lower y coords... (top of screen )