Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » I have a problem with animation

This thread is locked; no one can reply to it. rss feed Print
I have a problem with animation
Loki66
Member #17,089
May 2019

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

AceBlkwell
Member #13,038
July 2011
avatar

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.

dthompson
Member #5,749
April 2005
avatar

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. ;) )

______________________________________________________
Website. It was freakdesign.bafsoft.net.
This isn't a game!

Loki66
Member #17,089
May 2019

I looked at the guide of allegro.cc and github, but they are not detailed, there are no examples.
thanks anyway

MikiZX
Member #17,092
June 2019

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

Doctor Cop
Member #16,833
April 2018
avatar

MikiZX said:

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.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

dthompson
Member #5,749
April 2005
avatar

The wiki's quickstart has barebones code.

Edit: 🐌

______________________________________________________
Website. It was freakdesign.bafsoft.net.
This isn't a game!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

🐇

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'.

Loki66
Member #17,089
May 2019

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

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Loki66
Member #17,089
May 2019

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

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

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.

Doctor Cop
Member #16,833
April 2018
avatar

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.

Loki66
Member #17,089
May 2019

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 :)

dthompson
Member #5,749
April 2005
avatar

Gotta love integrated graphics ;)

Thanks dthompson and Edgar for this

No problem, it's what we do. (though Edgar does it far more.)

______________________________________________________
Website. It was freakdesign.bafsoft.net.
This isn't a game!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

GullRaDriel
Member #3,861
September 2003
avatar

He's even making me post again ^^

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Go to: