I created two small programs in which a circle is moved;
One has a circle created with primitives and another with a bitmap.
Their animation is very bad, it's not fluid. How can I improve these animations?
the two programs are attached.
Thank you
This is probably a silly question but are you drawing direct to screen or are you drawing to a buffer page first? A few of my first attempts at moving graphics I drew lines and squares directly to screen. Then I would have to blank out and draw next position. Wasn’t bad but led to some flicker. It didn’t look smooth.
I can't open .rar from my phone, but a couple things you might want to check:
Ensure your animation is updated only once per frame, using a timer.
Try enabling vsync.
If you're using Allegro 4, as AceBlkwell said, use double buffering. (or do the sensible thing and learn Allegro 5. )
I looked at the guide of allegro.cc and github, but they are not detailed, there are no examples.
thanks anyway
I've tried your source code (using a larger bitmap file I already had on my disk) and the animation appears good. I've tested on Windows10. Possibly you can provide more details regarding your system?
Also, possibly worth mentioning, my monitor is set to refresh at 75 Hz (you seem to be setting your timer to 60Hz which will not be the case on some systems).
EDIT: I am not sure to understand if you are looking for Allegro5 examples? I think you know about these but just in case, examples are included with the GitHub repo: https://github.com/liballeg/allegro5/tree/master/examples
EDIT: I am not sure to understand if you are looking for Allegro5 examples? I think you know about these but just in case, examples are included with the GitHub repo: https://github.com/liballeg/allegro5/tree/master/examples
What do you think, which example would be best fitting as a starter template for new projects?
As it's very hard for most people to write the same code over and over.
The wiki has a getting started guide you can find here :
https://wiki.allegro.cc/index.php?title=Getting_Started#Using_Allegro
The wiki's quickstart has barebones code.
Edit: 🐌
🐇
One thing you want to note is that you're moving very quickly in terms of pixels. 12 or 20 pixels per update? That's 720 or 1200 pixels per second, which is very fast, and unless you draw some kind of trail it will appear to 'teleport'.
Hi everyone
the operating system I use is windows 10 home edition;
the monitor has a frequency of 60 hz, the code I use to check the frequency is:
/******************************************************************************
display = al_create_display(SCREEN_W, SCREEN_H);
if(!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}
float fl_FPS = al_get_display_refresh_rate(display); // verifica la frequenza di aggiornamento del monitor
if (fl_FPS == 0) {
fl_FPS = 60; // se f_FPS e = 0 allora la frequenza è 60 Hz
}
timer = al_create_timer(1.0 / fl_FPS);
if(!timer) {
fprintf(stderr, "failed to create timer!\n");
}
/*********************************************************************
the excessive speed of animation is an example, but it is not fluid even at low speeds.
I'll look at the guide you suggested.
Thank you
https://en.wikipedia.org/wiki/Computer_animation
Please describe your problem exactly.
Is it tearing?
Is it jerking?
Is it teleporting across the screen?
Some people perceive things differently.
Also, if your timer is not synchronized with vsync, it will update during the middle of a screen redraw.
yes the image is tearing.
after reading the allegro.cc guide I added two lines
to the program I had attached:
/***************************************************************
al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE);
and
al_set_target_bitmap(al_get_backbuffer(display));
/****************************************************************
source code:
timer = al_create_timer(1.0 / FPS);
if(!timer) {
fprintf(stderr, "failed to create timer!\n");
return -1;
}
al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE);
display = al_create_display(SCREEN_W, SCREEN_H);
if(!display) {
fprintf(stderr, "failed to create display!\n");
al_destroy_timer(timer);
return -1;
}
btm_handle_player = al_load_bitmap("handlePl.bmp");
if(!btm_handle_player) {
fprintf(stderr, "failed to create handle bitmap!\n");
}
al_convert_mask_to_alpha(btm_handle_player,al_map_rgb(198,107,87));
al_set_target_bitmap(al_get_backbuffer(display));
/***************************************************************************
but nothing has changed.
moreover the animation is not fluid, that is, the bitmap does a small one
pause between one frame and another.
the bitmap moves as if there was a small lag at each frame.
I hope I was more precise, my English
is a translation of the Italian language made with google translate
Jerking is caused by a delay in rendering. This could be caused by missing the vsync and hitting the next one. That would instantly halve your framerate, as well as make it jerky.
I compiled your program against Allegro 5.2.5 and it ran fine for me. It did jerk just a little bit at first, but smoothed out quickly.
If enabling vsync didn't do anything, then either your graphics card has vsync disabled (in which case al_create_display should return 0), or you're out of sync.
Try synchronizing your timer with the display.
al_wait_for_vsync(); al_start_timer(timer);
Thanks dthompson and Edgar for this. This will help students to get started and I will not have to create a new template every time.
PROBLEM SOLVED
I tried to change some settings of the Intel graphics card. I selected "performance" on general settings.
Now the animation is ok.
Allegro5 was not a responsibility
My notebook is old and tired
thank you all for your availability
Gotta love integrated graphics
Thanks dthompson and Edgar for this
No problem, it's what we do. (though Edgar does it far more.)
That's because I refuse to let allegro.cc die.
:heart:
He's even making me post again ^^