Pergunta

I'm writing a game, and I've decided to use Allegro 5 and C/C++. I've worked out most of the bugs in my code so far, but I've come to the graphics and the mathematical computations that are included, and I'm stuck.

Here's the short version:

al_draw_rotated_bitmap(...) doesn't do much. Sometimes the image is onscreen, other times it isn't. I've verified that everything is loaded by drawing with al_draw_bitmap(...), and all is well, plus, no segfaults on drawing, so everything else works.

Just for your reference, the documentation says this as for the arguments of al_draw_rotated_bitmap(...):

al_draw_rotated_bitmap(ALLEGRO_BITMAP *bitmap, float cx, float cy, float dx, float dy, float angle, int flags)

Where cx is the X-center, cy is the Y-center, dx is the X-destination, dy is the Y-destination, angle is the angle to rotate by in radians, and flags are a combination of things telling Allegro if it should perform a +/- 90 degree turn on your bitmap.

I've tried many things, and none of them produce the desired results. I've tried making c&d(x,y) the same, different, setting dx&dy to a center of rotation, cx&cy to various points in the bitmap, in the backbuffer, on the center of rotation, etc. I'm probably just being really, really stupid and missing something here, but I haven't been able to figure it out. If anyone knows how this function works and would be willing to help me out with making it work, I would be very glad to have your advice. Thank you.

2014-04-08: I was asked to post code for the relevant function, here goes:

The actual drawing:

void renderPlayer(Player player)     {
cout << player.x << " " << player.y << endl;
float angle = 0;
al_draw_rotated_bitmap(player.tex, 200, 200, 0, 0, angle, NULL);
}

This struct is the definition of a Player:

struct Player   {
float x;
float y;
float r;
float t;
int radius;
int sizex;
int sizey;
int health;
int speed;
ALLEGRO_BITMAP *tex;
Weapon weapon;
};
Foi útil?

Solução

Okay, I'm not sure why this didn't work before... The way it should work is as follows:

al_draw_rotated_bitmap(ALLEGRO_BITMAP *yourbmp, int bitmap_coord_x, int bitmap_coord_y, int screen_coord_x, int screen_coord_y, float angle_in_radians, int flags)

That works fine for me! It still bewilders me why this didn't work at first... I suspect it was something else in my code.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top