Thursday 15 July 2010

c++ - Allegro mouse button released -


I want to create an algebra 5 program, where the cursor should change when the mouse button is pressed. As far as I understand this statement, events.type! = ALLEGRO_EVENT_MOUSE_BUTTON_UP never goes wrong but I do not understand why loop is closed after releasing the button Can you tell me where my fault is and if there is a better alternative method is?

  while (loop) {al_clear_to_color (al_map_rgb (0,0,0)); ALLEGRO_EVENT event; Al_wait_for_event (event_queue, and events); If (events.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {loop = false; } If (events.type == ALLEGRO_EVENT_MOUSE_AXES) {x = events.mouse.x; Y = events.mouse.y; Buffer = release; } If (events.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) while (events.type! = ALLEGRO_EVENT_MOUSE_BUTTON_UP) {x = events.mouse.x; Y = events.mouse.y; Al_draw_bitmap (pressed, X, Y, tap); Al_flip_display (); Al_clear_to_color (al_map_rgb (0, 0, 0)); } Al_draw_bitmap (release, x, y, tap); Al_flip_display (); }    

You do not check for new events within (events. Type! = ALLEGRO_EVENT_MOUSE_BUTTON_UP) the value of the loop and event. Type can never be changed

Your program is already running in a loop ( while (loop) {), there is no need to create another there, you should create a new variable that Depending on the status of ALLEGRO_EVENT_MOUSE_BUTTON_UP and the status of your mouse changes, etc ...

Something like this: (Pseudo Code!)

  While (loop) {al_clear_to_color (al_map_rgb (0,0,0)); ALLEGRO_EVENT event; _Bool change = false; Al_wait_for_event (event_queue, and events); If (events.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {loop = false; } If (events.type == ALLEGRO_EVENT_MOUSE_AXES) {x = events.mouse.x; Y = events.mouse.y; Buffer = release; } If (events.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) change = true; If (events.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) change = false; If (change) al_draw_bitmap (pressed, x, y, NULL); Other al_draw_bitmap (release, x, y, null); Al_clear_to_color (al_map_rgb (0, 0, 0)); Al_flip_display (); }    

No comments:

Post a Comment