Sign in to follow this  

[Allegro]BITMAP* referece ignoring the double buffering

This topic is 3565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making a project using Allegro, and in this project i made a class named CSprite to encapsulate a sprite(really? XD). I'm using one buffer to do the drawing on the screen, so i need to pass a reference to this buffer so my animation function of my CSprite class can be able to draw on this buffer. I do that and it worked, but completely ignoring the double buffering (i.e. The images been draw keep flashing on screen). follows the code: the function that captures the buffer:

void CSprite::SetBuffer(BITMAP* buff)
{
buffer=buff; //buffer is a public BITMAP* variable
}


the function that draws on the buffer:

void CSprite::AnimateSequence(std::vector<BITMAP*>sequence,short int delay,int x,int y)
{
unsigned int size=sequence.size();

if(delay==mdelay)
{
if (cont>size-1)
   {
  cont=0;
   }
  mdelay=0;// a variable to control the velocity of animation
 draw_sprite(buffer,sequence.at(cont),x,y-(sequence.at(cont)->h));
  cont++;
}
mdelay++;
}


the function that truly animates the sprite:
...
canvas=create_bitmap(SCREEN_W,SCREEN_H);
anima.SetBuffer(canvas);

	while (!key[KEY_ESC])
	{
      if (cont>=control) //cont is a variable incremented by a timer
      {
       anima.AnimateSequence(oi3,4,200,200+(oi3.at(0)->h));
       blit(canvas, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
       clear_to_color(canvas, makecol(255,255,255));
        control=cont+1;
      }

	}

Is this the right way to do it? Am i doing something wrong?

Share this post


Link to post
Share on other sites
not sure bout this but it might help.
there is a function called

rest(unsigned int time);


It slows down your application, i think.
try sticking it in the loop after the if block (if (cont>=control))
pass a value of something like 10 to the function.
see what happens.

Share this post


Link to post
Share on other sites

This topic is 3565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this