1

I'm a newbie to allegro so this may be a simple question.

I'm wondering if there is a way to move allegro shapes by x,y without filling the circle i made with a black circle and making a new circle.

Currently i have a while loop that moves the circle by moving filling the current one with a black circle and making a new one with x and y that are a little different i'd like to know if there is a way to move allegro shapes by x,y because it seems to make my game slow.

Here is a current while with this way:

int x=100;
int y = 100;
int tempX,tempY; 
 while(1)
{
tempX=x;
tempY=y;
    circlefill ( screen, tempX, tempY, 20, makecol( 0,0, 0));
    circlefill ( screen, x, y, 20, makecol( 0, 0, 255))
x+=10;
y+=10;
}

Thanks

progc123
  • 15
  • 4

2 Answers2

0

You need to use a buffer.

After you set your graphics mode, create a bitmap that is SCREEN_W,SCREEN_H big. Then on every frame, clear that bitmap, draw your blue circle to it at x, y, then draw the buffer to the screen.

I suggest that you take a look at the many examples that come with Allegro or read tutorials, because there are many elementary but important things that you need to learn.

Also, I would highly recommend using Allegro 5 since it is actively developed and has an API that is far more suitable for modern hardware.

Matthew
  • 47,584
  • 11
  • 86
  • 98
0

As Matthew said, you want to use a buffer, which is like a virtual screen where you can write all the bitmaps you want before showing it on the screen, it has to be the same size as your screen size.

Forget TempX and TempY, and instead of calling circlefill (screen, x, y, 20, makecol(0,0,255)) you first make a bitmap (usually named buffer, heh..) and from now you draw all your graphics directly to it, so dont use screen use buffer. When you finish each frame,you "blit" this buffer to the screen like this:

blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);

and then you just call clear_bitmap(buffer) and start drawing again to it and repeat. That way you dont have to keep track of an objects previous position to erase it before drawing it again in its new position, imagine the hit the CPU would have if instead of a black background you had to erase and fill the backround with another piece of a bitmap each time you move something?

rlam12
  • 603
  • 5
  • 16