Hello, I want to create a menu for my game and I have some questions.
First I wanted the mouse to move over the word, it would change color, but when it changes color if I take the mouse out of the word it does not return its original color (white)
The way I did it does not appear very accurate because almost any movement of the mouse causes the word to change color.
maybe I'm putting the wrong update line, I've already put it in several different places of the program, if you can clarify where to put it would also be great.
Another question is: will it be necessary to create different windows for when I click, for example, to start the game or to change its audio settings?
How could a menu be made? I am new at programming with the library.
my code:
Vieira,
please use code-tags (see Formatting Help) if you are posting code to make it more readable.
If I understand correctly you try to make a game menu that changes color based on the mouse input. This can be achieved without creating different windows. Also, you don't need to include/use the "allegro_native_dialog" for this.
Take a look at that line:
if(ev.mouse.y= 280,ev.mouse.x=780)
Here, you are doing an assignment rather than a comparison. I think what you want to do is:
if(ev.mouse.y==280,ev.mouse.x==780)
Also, you probably need to make the comparison like this:
if ((ev.mouse.y==280) && (ev.mouse.x==780))
Then there are two if-statements that are exactly the same so the second if-statement will never be checked.
else if (ev.type == ALLEGRO_EVENT_MOUSE_AXES) { if(ev.mouse.y= 280,ev.mouse.x=780) { al_draw_text(mainfontmenor,al_map_rgb(250,0,0),780,280,NULL,"InIcIaR"); } else if (ev.mouse.y= 280,ev.mouse.x=780) { al_draw_text(mainfontmenor,al_map_rgb(250,250,250),780,280,NULL,"InIcIaR"); al_flip_display(); }
I think what you wanted to to here is something like this:
else if (ev.type == ALLEGRO_EVENT_MOUSE_AXES) { if ((ev.mouse.y==280) && (ev.mouse.x==780)) { al_draw_text(mainfontmenor,al_map_rgb(250,0,0),780,280,NULL,"InIcIaR"); } else { al_draw_text(mainfontmenor,al_map_rgb(250,250,250),780,280,NULL,"InIcIaR"); al_flip_display(); }
See if that helps ...
Hello, Thanks for the trouble!
It worked in parts, however when I added logic (and) it did not work, so I just chose to make use of the comma.
However, the word only turns red at a specific point on the screen, I think it would be better to do in an area that covers the word, I thought of making less equal to xxx, but I do not know if this is the best way to do
Games are just data and instructions. If you think in terms of those two things, then you can program anything.
First, the data - the word position and area.
Second, the instruction - if the mouse is over the word area, display in red, else display in white.
Now just code it.
The word has a rectangle. The mouse has a position. You can check if the mouse is inside the rectangle. Then you can decide whether to display red or white text.
In my own Deluxe Pacman 2 game, I simply check each button and compare the rectangular area it occupies with the mouse position. If the mouse isn't over it, I draw a blue button, if it is over it, I draw a red button, if you click and are over it, I draw a red button that appears depressed. I created three button graphics for each one. It's really simple to code. I have menu button routines for adding new buttons and storing their location for checks later on.
Thanks,
I understood that the words occupy the dimensions, after that, it was really easier to understand how it does
Please use <code>code goes here...</code> tags for displaying code. Makes it appear in a nice formatted window.