Search code examples
allegro

is there a way to move shapes by x and y in Allegro 4.2?


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


Solution

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