Hopefully nobody steals what I have been working on, but in an effort to make things potentially easier for people to help me, here's the GMK: http://www.host-a.ne...tsArrays2.5.gmk
Okay, rephrasing and reorganizing some things so hopefully you wont have to run through the entire thread. Objects are color coded to be more distinguishable.
I am making a tower defense game. I wanted there to be a minimalist style menu system so that your screen is uncluttered whenever something isnt relevant (Basically, things fade out when not in use). My current problem exists with menu's. I have one menu set up in the top left corner that allows the player to simply overview towers and eventually their stats. When you hover over the square for the menu, it expands and a cascade of buttons comes down from it (9 buttons in total). Once scrolled over with the mouse there is a sprite drawn over the button to show which one you are currently over, this is called spr_select. I will post the code for obj_button (The square you scroll over) and obj_menu_button (the buttons that appear).
obj_button:
Create Event:
show=false; alpha=0; select=0; time=20; // time the menu should use to move into place
Step Event:
// this controls image_alpha - max and min is to keep it between 0 and 1
alpha = min(1,max(0,alpha + (show-!show)*1/time))
image_alpha = 1-alpha; //alpha for menu - when it is gone then this should be clear
with(obj_menu_button)image_alpha = other.alpha*1; // give menu buttons the half the alpha. Old Value was 0.5
if show=true{
// get the button number you are over if within menu area
if mouse_x>0 && mouse_x<32
&& mouse_y>0 && mouse_y<32*9{
select = mouse_y div 32;
}
// if button pressed
if mouse_check_button_pressed(mb_left){
show=false; // start closing down
with(obj_menu_button){
alarm[1]=other.time; // tell all menu buttons to start alarm 1
vspeed=-((image_index*32)/other.time); // and move back up
}
}
}Mouse Enter:
if show=false{
show=true; // start showing buttons
for(i=1;i<10;i+=1)instance_create(x,y,obj_menu_button) // create the buttons
image_yscale = image_yscale*(9)
}Mouse Leave:
if show=true{
show=false; // start hiding buttons
with(obj_menu_button){
alarm[1]=other.time; // tell all menu buttons to start alarm 1 which gets rid of them
vspeed=-((image_index*32)/other.time); // and move back up
}
image_yscale = image_yscale / (9) //Scale the main button back to 32x32
//put it outside of the width(obj_menu_button)
}
Draw Event:// draw the button
draw_sprite_ext(sprite_index,image_index,x,y,1,1,0,c_white,image_alpha) //x,y,1,1,0,c_white...
// draw the info
draw_set_color(c_black)
draw_set_alpha(1)
draw_text(x+64,y,string(show)+ ' ' + string(alpha)+'#'+tower_text[(select+1)mod 10]) //Changes position of 'select 0 or 1' , 'alpha #' , and the name of the tower.
// make the buttons draw the text
with(obj_menu_button){
draw_set_alpha(image_alpha) // using the alpha it currently has
draw_text(x+36,y,string(image_index+1)) // draw its number +1 - This is the number beside the tower to signify which key to hit.
if other.select = image_index draw_sprite(spr_select,0,x,y) // if selected - then draw selection rectangle
}
obj_menu_button:
Create Event:
image_index = instance_number(object_index)-1
image_speed=0;
if image_index < 0 { instance_destroy(); exit; }
alarm[0]=obj_button.time;
vspeed = (image_index*32)/alarm[0];Alarm 0:
y=image_index*32 speed=0;
Alarm 1:
instance_destroy()
Now, my problem arises when I want to create the same system, but one that is activated through right clicking and can be placed anywhere on the screen. This is my current setup involving obj_rightclick_button (equal to obj_button) and obj_right_menu_button (equal to obj_menu_button) and spr_select2 (Same as spr_select but with different coloring). Most of the code is exactly the same with a few number tweaks here and there. The main problem is that spr_select2 will not draw over the scrolled over button.
Within the step event of obj_rightclick_button is:
if mouse_x>0 && mouse_x<928 && mouse_y>0 && mouse_y<672
The numbers there are purely experimental. I tried that to see if I could give it a range of the whole games viewing area to see if it made a difference.
Anyways, this menu has two main differences of vanishing once the right mouse button is released and of course being much smaller (only two buttons)
Here is applicable code:
obj_rightclick_button:
Create Event:
//Same stuff, different location show=true; alpha=0; select=0; time=20; // time the menu should use to move into place for(i=1;i<3;i+=1)instance_create(x-16,y-16,obj_right_menu_button) // create the buttons right as instance is created. using mouse enter didnt work when the mouse was already inside image_yscale = image_yscale*(2) //This menu is only 2 squares big
Step Event:
// this controls image_alpha - max and min is to keep it between 0 and 1
alpha = min(1,max(0,alpha + (show-!show)*1/time))
image_alpha = 1-alpha; //alpha for menu - when it is gone then this should be clear
with(obj_menu_button)image_alpha = other.alpha*1; // give menu buttons the half the alpha. Old Value was 0.5
// this controls image_alpha - max and min is to keep it between 0 and 1
alpha = min(1,max(0,alpha + (show-!show)*1/time))
//image_alpha = 1-alpha; //alpha for menu - when it is gone then this should be clear
with(obj_right_menu_button)image_alpha = other.alpha*1; // give menu buttons the half the alpha. Old Value was 0.5
if show=true{
// get the button number you are over if within menu area
if mouse_x>0 && mouse_x<928
&& mouse_y>0 && mouse_y<672
select = mouse_x && mouse_y;
}Global Right Released:
if show=true{
show=false; // start hiding buttons
with(obj_right_menu_button){
alarm[1]=other.time; // tell all menu buttons to start alarm 1 which gets rid of them
vspeed=-((image_index*32)/other.time); // and move back up
}
image_yscale = image_yscale / (2) //Scale the main button back to 32x32
//put it outside of the with(obj_menu_button)
instance_destroy(); //Destroys the menu after being done to allow the instance_number check on obj_create's right click event to reset to 0.
}Draw Event:
//I havent fiddled much at all with this yet. Only thing that got changed was the 'with' statement and 'spr_select' now has a 2, to correspond to my eventual use of a different style button.
// draw the button
draw_sprite_ext(sprite_index,image_index,x,y,1,1,0,c_white,image_alpha) //x,y,1,1,0,c_white...
// draw the info
draw_set_color(c_black)
draw_set_alpha(1)
draw_text(x+64,y,string(show)+ ' ' + string(alpha)+'#'+tower_text[(select+1)mod 10]) //Changes position of 'select 0 or 1' , 'alpha #' , and the name of the tower.
// make the buttons draw the text
with(obj_right_menu_button){
draw_set_alpha(image_alpha) // using the alpha it currently has
draw_text(x+36,y,string(image_index+1)) // draw its number +1 - This is the number beside the tower to signify which key to hit.
if other.select = image_index draw_sprite(spr_select2,0,x,y) // if selected - then draw selection rectangle
}obj_right_menu_button:
Create Event:
image_index = instance_number(object_index)-1; //There can clearly only be one of these at a time. Releasing right mouse button, causes this to destroy itself.
image_speed=0;
//So image_index=0;
if image_index < 0 { instance_destroy(); exit; }
alarm[0]=obj_rightclick_button.time; //Changed to new instance. That is all. No further code touched on buttons.
vspeed = (image_index*32)/alarm[0];Alarm 0:
speed=0;
Alarm 1:
instance_destroy()
Edited by Zealot644, 06 February 2012 - 08:02 PM.











