Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » double buffering

This thread is locked; no one can reply to it. rss feed Print
double buffering
ferkaluk
Member #7,422
June 2006
avatar

Hi everyone
I want to use double buffering in code for moving a sprite (texture)
but it don,t look good, the movig of sprite is non soft.

please look for this code and give me advice what to correct:

BITMAP *buffer = create_bitmap(SCREEN_W, SCREEN_H);
do
{
clear(buffer);
clear_to_color(buffer, 15);
if(key[KEY_LEFT]) i-=4;
if(key[KEY_RIGHT]) i+=4;
if(key[KEY_UP]) j-=4;
if(key[KEY_DOWN]) j+=4;
draw_sprite(buffer, the_image, i, j);// clear_keybuf();  rest(20);
vsync();
blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
}while(!key[KEY_ESC]);

Nils Fagerburg
Member #7,193
May 2006
avatar

What do you mean by "not soft"? Perhaps you are moving your sprite too fast.
Also you don't need the clear(buffer); line since you are doing clear_to_color() right after it.

--
There's no place like ~.

vixinu
Member #7,343
June 2006
avatar

#1..........spell check

#2..........do you mean it just jumps to your destination?

Elverion
Member #6,239
September 2005
avatar

Also, look into timers and separate your logic from drawing code. The forum search appears to be broken right now, or I'd help find a few useful topics. So, just read the manual and look up install_timer_ex and related functions. You might also Google search for Allegro timer tutorials.

Without separating your logic and drawing, you are putting extra, unnecessary processing power into drawing when it doesn't need to be redrawn. Also, minor fluctuations in the process time slice allotment would cause minor hiccups during game play. You might also want to look into vsync() to help smooth things out.

http://gpwiki.org/index.php/Allegro:Tutorials:Basics
http://www.loomsoft.net/resources/alltut/alltut_lesson6.htm <-- highly recommended.

--
SolarStrike Software - MicroMacro home - Automation software.

neil dwyer
Member #7,237
May 2006

If non soft means jumpy it maybe it is because you are going four pixels at a time with a small screen resolution.

Edit: Also make your code a little more readable, you should never call a variable 'j'.

ferkaluk
Member #7,422
June 2006
avatar

thx for all comments

my code doesn't have a timer (maybe this is a reason)
i will check tutorials and include the timer in code

there is the code and exe(program) (310KB)
http://www.ferkaluk.vel.pl/allegro/BMP.ZIP

//edit
sory for my weak english ::)

vixinu
Member #7,343
June 2006
avatar

To jest wspaniałe jeżeli wasz Język angielski nie jest bardzo dobry. pomyślę (obmyślił) was byliście po prostu (dopiero co) niedbały Amerykanin. Wy jesteście mały (niewielka ilość; trochę) lepszy (lepiej) niż niedbały Amerykanin, chociaż.

CursedTyrant
Member #7,080
April 2006
avatar

Please tell me you're not from Poland ::)

Also, that translator sucks ;D

---------
Signature.
----
[My Website] | [My YouTube Channel]

ferkaluk
Member #7,422
June 2006
avatar

hmm vixinu
what do you want to tell me ??
'cuz ???

CursedTyrant
Member #7,080
April 2006
avatar

I guess he's the only one who has any idea what he is talking about ;D

---------
Signature.
----
[My Website] | [My YouTube Channel]

ferkaluk
Member #7,422
June 2006
avatar

tak myślę , może popis jakiś czy co

LennyLen
Member #5,313
December 2004
avatar

Quote:

I guess he's the only one who has any idea what he is talking about

Based on most of his posts, I doubt he does either.

vixinu
Member #7,343
June 2006
avatar

I was using a bad translator, but the only one I could find: poltran.com. No, I'm from the USA. So how 'bout we just start up a 'Complain about vixinu' thread? I promise not to interfere and get mad about it, in fact, I encourage it!!!>:(

CursedTyrant
Member #7,080
April 2006
avatar

At least you learnt a lesson. Never use translators. They are evil! ;)

---------
Signature.
----
[My Website] | [My YouTube Channel]

LennyLen
Member #5,313
December 2004
avatar

Quote:

At least you learnt a lesson. Never use translators. They are evil!

Correction... don't use them to translate your own words to another language. When it comes to trying to get the gist of the meaning of a passage written in a foreign language, they are a great tool.

vixinu
Member #7,343
June 2006
avatar

Still reccomend the make fun of vixinu thred. I wasn't kidding!;D

Go to: