-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hola:
Tengo el siguiente problema.
Cuando trato de "mover" una imagen utilizando el cursor; esa imagen parpadea
constantemente.
No se cómo solucionarlo. Se me ocurre que tal vez debería usar una función de
temporización, pero no tengo ni idea de cómo hacerlo. La ayuda de Allegro es
demasiado técnica para mí.
Adjunto el código que hice hasta ahora.
¿Saben de algún tutorial en español que explique un poco más la programación
de juegos con Allegro? Hasta ahora solamente encontré uno, y explica muy
poco, casi nada.
Desde ya muchas gracias.
#include "allegro.h"
int main(int argc, char *argv[])
{
PALETTE pal;
int x, y, x_anterior, y_anterior;
BITMAP *image;
BITMAP *buffer; //PARA EL MOVIMIENTO
allegro_init();
install_keyboard();
set_color_depth(8);
if (set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0) != 0) {
allegro_message("Error al establecer el modo gráfico\n%s\n",allegro_error);
return 1;
}
image =load_bitmap("allegro.pcx", pal);
set_palette(pal);
//-----------------------------------------------------------------------//
// TODO LO QUE SIGUE ES AGREGADO PARA EL MOVIMIENTO
//-----------------------------------------------------------------------//
buffer = create_bitmap (image -> w, image -> h);
clear(buffer); //LIMPIO EL BUFFER
x = SCREEN_W/2;
y = SCREEN_H/2;
while (!key[KEY_ESC]) {
if (key[KEY_UP]) y--;
if (key[KEY_DOWN]) y++;
if (key[KEY_LEFT]) x--;
if (key[KEY_RIGHT]) x++;
if (x<0) x=x_anterior;
if (x>SCREEN_W-image->w) x=x_anterior;
if (y<0) y=y_anterior;
if (y>SCREEN_H-image->h) y=y_anterior;
if ((x_anterior != x) || (y_anterior != x)) {
blit (buffer, screen, 0, 0, x_anterior, y_anterior, buffer -> w, buffer -> h);
blit (screen, buffer, x, y, 0, 0, buffer -> w, buffer -> h);
draw_sprite ( screen, image, x, y);
}
x_anterior = x;
y_anterior = y;
}
return 0;
}
END_OF_MAIN();
- --
Llave Gnupg en:
http://pgp.rediris.es:11371/pks/lookup?op=get&search=0x6F1FD83E
Key fingerprint = F619 9CB9 8E42 0287 8386 D2ED AEBA 0FC5 6F1F D83E
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iEYEARECAAYFAj9Sj7YACgkQrroPxW8f2D59/QCfeEzdTu3WMNuaRb+G2BC0yqEK
G9gAn0mjTjkBP+IeoqYvuUN7WvQSCMzw
=qsEF
-----END PGP SIGNATURE-----