Help using mouse events in creating a Menu
Luna Wu
#SelectExpand
1int x = 1; 2 3#include <stdio.h> 4 5#include <allegro5/allegro.h> 6 7#include <allegro5/allegro_font.h> 8#include <allegro5/allegro_ttf.h> 9#include <allegro5/allegro_color.h> 10#include <allegro5/color.h> 11#include <iostream> 12 13int main(){ 14 al_init(); 15 al_init_font_addon(); 16 al_init_ttf_addon(); 17 ALLEGRO_EVENT events; 18 ALLEGRO_EVENT_QUEUE *eventqueue; 19 eventqueue = al_create_event_queue(); 20 al_install_keyboard(); 21 al_register_event_source(eventqueue, al_get_keyboard_event_source()); 22 23 ALLEGRO_DISPLAY *display = al_create_display(640, 480); 24 ALLEGRO_FONT *font = al_load_ttf_font("homewts.ttf", 30, 0); 25 al_register_event_source(eventqueue, al_get_display_event_source(display)); 26 27 28 al_clear_to_color(al_map_rgb(255, 255, 0)); 29 al_draw_text(font, al_map_rgb(255, 0,0), 640 / 2, (480 / 4), ALLEGRO_ALIGN_CENTRE, "Start"); 30 al_draw_text(font, al_map_rgb(255, 0, 0), 640 / 2, (480/2), ALLEGRO_ALIGN_CENTRE, "EXIT"); 31 al_flip_display(); 32 al_install_mouse(); 33 al_wait_for_event(eventqueue, &events); 34 if (events.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP){ 35 if (events.mouse.x >= (640 / 2) && events.mouse.y >= (480 / 2)){ 36 std::cout << "START!"; 37 } 38 } 39 al_rest(10.0); 40 al_destroy_display(display); 41 return 0; 42}

Hello guys, I've been trying to create a main menu using allegro5 and c++, but I can't figure out why my mouse events aren't working, can anybody please help?

SiegeLord

After calling al_install_mouse() you need to add al_register_event_source(eventqueue, al_get_mouse_event_source())

Luna Wu

Thanks!

Thread #616183. Printed from Allegro.cc