Mail Archives: djgpp/1999/08/17/11:36:05
What is a fast way to do page flipping? I made a fast program to teach
myself allegro, but page flipping goes REALLY slow:
As you can see, I'm using scroll_screen to switch between the top and bottom
of a 320x480 screen, with a 320x240 viewport, but normally the little guy
that is moving around goes too fast to control, but with my page flipping
routines, he slows down to a crawl.
#include <allegro.h>
#define MASK_COLOR_8 0
int CURRENT_SCREEN = 0;
void page_flip()
{
scroll_screen(0, CURRENT_SCREEN * 240);
CURRENT_SCREEN = !CURRENT_SCREEN;
clear(screen);
}
class player
{
public:
float x;
float y;
float speed;
BITMAP *image;
player()
{
PALETTE p;
image = load_bmp("player.bmp", p); // this is a small bmp of a
little guy
set_palette(p);
x = 60;
y = 60;
speed = 1;
}
void inline move()
{
if(key[KEY_UP] && y > 10)
y -= speed;
if(key[KEY_DOWN] && y < 190)
y += speed;
if(key[KEY_LEFT] && x > 10)
x -= speed;
if(key[KEY_RIGHT] && x < 270)
x += speed;
}
void inline draw()
{
draw_sprite(screen, image, (int)x, (int)y + CURRENT_SCREEN *
240);
}
};
void main()
{
allegro_init();
install_keyboard();
install_mouse();
set_gfx_mode(GFX_MODEX, 320, 240, 320, 480);
set_clip(screen, 0, 0, 319, 479);
clear(screen);
player bob;
while(!key[KEY_ENTER])
{
bob.move();
bob.draw();
page_flip();
}
}
- Raw text -