![]() |
|
Making Buttons |
Zephelin
Member #12,952
June 2011
|
How can I find a tutorial for making buttons and setting events happening when clicked EDIT: Also another problem with my compiler, thanks if you can tell why; When I compile using Release option in VS, I get; 1>------ Build started: Project: Allegro, Configuration: Release Win32 ------ Thought I don't get any with Debug option, why? |
RPGillespie
Member #12,946
June 2011
|
I used this logic to code all of my buttons (the actual sprites were created in GIMP/Powerpoint): 1 //x represents the x coordinate of the bitmap
2 //y represents the y coordinate of the bitmap
3 //state is of type ALLEGRO_MOUSE_STATE
4 //mouse_hovering and left_down are bools
5 //setDrawFrame() is a function I wrote to switch which bitmap is being drawn
6 //This code goes inside the update function of your button object
7
8 //updates state, which is a struct that holds mouse information such as its coordinates on the screen
9 al_get_mouse_state(&state);
10
11
12 //Checks if mouse is hovering over the sprite.
13 //if so, it will start drawing a different sprite (kind of like when you hover your mouse over any of your browser buttons
14 if (state.x < (x+30) && state.x > x && state.y < (y+30) && state.y > y)
15 {
16 setDrawFrame(1);
17 mouse_hovering = true;
18 }
19 else
20 {
21 setDrawFrame(0);
22 mouse_hovering = false;
23 }
24
25 //If the left mouse button is being pressed and the mouse is hovering over the button, set a flag;
26 if ((state.buttons & 1) && mouse_hovering)
27 {
28 //you could also set the sprite to yet another frame here, one of the button being depressed.
29 left_down = true;
30 }
31
32 //If the flag is on and the mouse button is no longer being clicked, you know the user has released the mouse button
33 if (left_down && !al_mouse_button_down(&state, 1))
34 {
35 //don't forget to switch the sprite back to the non-depressed version here.
36 left_down = false; //don't forget to reset the flag
37
38
39 //here goes whatever code you wanted to execute when the button was pressed//
40 }
As for your other problem, I think it's good practice to code a little, then test, then code a little, then test. Using this approach, I never have to deal with more than 1 or 2 errors at a time, and it's really easy to tell where the error is coming from when it worked 2 seconds ago, you coded a little, and now it's broken. My Games: |
Zephelin
Member #12,952
June 2011
|
What's the identifier of state? |
RPGillespie
Member #12,946
June 2011
|
RPGillespie said: //state is of type ALLEGRO_MOUSE_STATE I put it in the comments at the top My Games: |
Karadoc ~~
Member #2,749
September 2002
![]() |
The errors in 'release' mode are saying that certain allegro functions are not being found in your final problem. unresolved external symbol means a function was declared and used, but not defined. To fix the problem, you need to link to the appropriate libraries which contain the function definitions. The reason it is happening to you in release mode and not debug mode is that you are using different versions of the allegro library. Probably the static version for release and the dynamically linked version for debug. Although you are using MSVC, you'll probably find what you need to know here. ----------- |
Zephelin
Member #12,952
June 2011
|
1>------ Build started: Project: Allegro, Configuration: Debug Win32 ------ |
AMCerasoli
Member #11,955
May 2010
![]() |
Karadoc ~~ said: Although you are using MSVC, you'll probably find what you need to know here [www.cerebrospain.com]. Well, actually I put the tutorial there when I didn't know that there was a wiki about Allegro, well, to be honest I did know that there was a wiki, but I didn't know how to use it, and was a complete disaster, now still being a disaster but not complete
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Zephelin said: 1>c:\documents and settings\quarynn\my documents\visual studio 2010\projects\allegro\allegro\main.cpp(6): warning C4273: 'al_init_image_addon' : inconsistent dll linkage 1>c:\program files\microsoft visual studio 10.0\vc\include\allegro5\allegro_image.h(32) : see previous definition of 'al_init_image_addon' It sounds like you're including two different definitions of al_init_image_addon, but A5 should be using include guards so I don't know how that is possible. Zephelin said: 'al_get_mouse_state' : cannot convert parameter 1 from 'ALLEGRO_MOUSE_STATE **' to 'ALLEGRO_MOUSE_STATE *' It says exactly what it means - you are passing the address of an ALLEGRO_MOUSE_STATE* when it expects an ALLEGRO_MOUSE_STATE*. Zephelin said:
left of '.x' must have class/struct/union You're trying to use '.' to access a pointer. You have to use '->' to access member variables through a pointer. After you fix these errors, if you still have errors, post your full code and the errors you get with it. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|