|
Allegro 5.2 Image Xcode |
motyas
Member #16,305
April 2016
|
Hello guys, i'm here because i need your help. I've tried about one week including images in my allegro code, but i can't! My platform is Xcode, someone knows how to do it? (I want to put the image in the mouse cursor) This is my code: 1#include <allegro5/allegro.h>
2#include <allegro5/allegro_primitives.h>
3#include <allegro5/allegro_image.h>
4#include <allegro5/allegro_native_dialog.h>
5
6int main(int argc, char *argv[]){
7
8 const int screenW = 640, screenH = 480;
9 int pos_x = screenW / 2, pos_y = screenH / 2;
10 ALLEGRO_BITMAP * player = NULL;
11 ALLEGRO_COLOR electricBlue = al_map_rgb(44, 117, 255);
12 ALLEGRO_COLOR yellow = al_map_rgb(255, 255, 0);
13 ALLEGRO_COLOR playerColor = electricBlue;
14
15 ALLEGRO_DISPLAY * display = NULL;
16 ALLEGRO_EVENT_QUEUE * event_queue = NULL;
17 bool done = false;
18
19 if(!al_init()){
20 al_show_native_message_box(NULL, NULL, NULL, "Allegro cannot initialize successfully", NULL, ALLEGRO_MESSAGEBOX_ERROR);
21 return -1;
22 }
23
24 display = al_create_display(screenW, screenH);
25 if(!display){
26 al_show_native_message_box(NULL, NULL, NULL, "Display wasnt't created successfully", NULL, ALLEGRO_MESSAGEBOX_ERROR);
27 return -1;
28 }
29
30 al_init_image_addon();
31 al_install_mouse();
32
33 player = al_load_bitmap("/Users/matias/Desktop/Matías/C++/Programas/AllegroFiles/Tutorial/Allegro_Image/Allegro_Image/resources/player.png");
34
35 event_queue = al_create_event_queue();
36
37 al_register_event_source(event_queue, al_get_display_event_source(display));
38 al_register_event_source(event_queue, al_get_mouse_event_source());
39
40 al_hide_mouse_cursor(display);
41
42 while(!done){
43
44 ALLEGRO_EVENT ev;
45 al_wait_for_event(event_queue, &ev);
46
47 if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
48 done = true;
49 }
50 else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES){
51 pos_x = ev.mouse.x;
52 pos_y = ev.mouse.y;
53 }
54 else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN){
55 if(ev.mouse.button & 1){
56 playerColor = electricBlue;
57 }
58 else if(ev.mouse.button & 2){
59 playerColor = yellow;
60 }
61 }
62
63 al_draw_bitmap(player, pos_x, pos_y, NULL);
64
65 al_flip_display();
66 al_map_rgb(0, 0, 0);
67
68 }
69
70 al_destroy_display(display);
71 al_destroy_bitmap(player);
72
73 return 0;
74}
I attached an image of my error to this post... |
hareball
Member #16,323
May 2016
|
Hi, I think you have a problem with your clear screen code. There should be a should be al_clear_to_color(al_map_rgb(0, 0, 0)); just before you draw. Put it on line 62 (before al_draw_bitmap). You can remove your line 66 - al_map_rgb(0, 0, 0) line, I don't think that does anything. |
motyas
Member #16,305
April 2016
|
You're a master! Thank you very much |
|