Game slow down from drawing player

I've been making a shooter game and have just added sprites for players. After I added drawing the players, the game has been sorta slow and sometimes takes 5-15 seconds to close after I click X. Also, it uses a lot more CPU when the drawing part is in. When I take the drawing code out, the game is normal speed again. Is there anything wrong with this code? I have to take a region from a sprite sheet, then rotate it. Is there something wrong with the way I did it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
ALLEGRO_BITMAP *buffer = al_create_bitmap(64, 64);
al_set_target_bitmap(buffer);
if (players[i].type == 0)
	al_draw_bitmap_region(playerImage1, player.width * players[i].frame, 0, player.width, player.height, 0, 0, 0);
else if (players[i].type == 1)
	al_draw_bitmap_region(playerImage2, player.width * players[i].frame, 0, player.width, player.height, 0, 0, 0);

al_set_target_bitmap(al_get_backbuffer(display));
al_draw_rotated_bitmap(buffer, player.width / 2, player.height / 2, players[i].x, players[i].y, players[i].dir, NULL);

double sintheta = sin(players[i].dir);
double costheta = cos(players[i].dir);

players[i].gunX = players[i].x + (players[i].gunOffX * cos(players[i].dir)) - (players[i].gunOffY * sin(players[i].dir)); 
players[i].gunY = players[i].y + (players[i].gunOffY * cos(players[i].dir)) + (players[i].gunOffX * sin(players[i].dir));

ALLEGRO_BITMAP *buffer2 = al_create_bitmap(64, 64);
al_set_target_bitmap(buffer2);
buffer = NULL;
al_draw_bitmap_region(weaponImage, 64 * players[i].weapon, 0, 64, 64, 0, 0, 0);
al_set_target_bitmap(al_get_backbuffer(display));
al_draw_rotated_bitmap(buffer2, 32, 32, players[i].gunX, players[i].gunY, players[i].dir, 0);
Last edited on
Topic archived. No new replies allowed.