GML Help with highlighting a player's choice

Discussion in 'Programming' started by Smallmak, Jun 14, 2019 at 5:44 PM.

  1. Smallmak

    Smallmak Member

    Joined:
    May 28, 2019
    Posts:
    6
    In my game the player is able to open up a menu with square icons of their available skills. I have it so that when the play right clicks a skill is selected and they can use it, I also have made it so that the skills under their cursor light up. however I want it so that when they right click sprite7 is draw over the skill icon that the mouse is hovering over
    here is what I have so far. if I need to post more info let me know

    ( "MBR_Selected" is true when the play right clicks. I want it so that when they right click sprite7 is drawn over their selected talent aka the talent the mouse is hovering over. any ideas on how I can accomplish this? )

    Code:
    var ii, ix, iy, xx, yy, sx, sy, tal_grid, sTalent;
    ii = 0; ix = 0; iy = 0; xx = 0; yy = 0;  tal_grid = ds_Tal; sTalent = 0;
    
    
    repeat(talSlots){
           xx = slotsX + ((cellSize+x_buffer) * ix * scale);
           yy = slotsY + ((cellSize+y_buffer) * iy * scale);
       //x,y,location
       sTalent = ds_Tal[# 0, ii]
       sx = (sTalent mod talColumns) *cellSize;
       sy = (sTalent div talColumns) *cellSize;
      
       draw_sprite_part_ext(
               sprite6, 0, sx, sy, cellSize,cellSize,
               xx,yy, scale,  scale, c_white,1);
              
       switch(ii){
       case selected_tal:
           if(sTalent > 0){
               gpu_set_blendmode(bm_add);
               draw_sprite_part_ext(sprite6,0,sx,sy,cellSize,cellSize,xx,yy,
               scale,scale,c_white,0.5);
               gpu_set_blendmode(bm_normal);
          
            break; }
       }
       ii += 1;
       ix = ii mod talColumns;
       iy = ii div talColumns;
      
       }
    
    
    
       if(MBR_Selected){draw_sprite_part_ext(sprite7,0,0,0,cellSize,cellSize,xx ,yy ,
       scale,scale,c_white,1 );}
    
     
  2. the_dude_abides

    the_dude_abides Member

    Joined:
    Jun 23, 2016
    Posts:
    535
    In the create event make a permanent variable, and set it to false. Create two more for holding an x and y position. Right click sets the first variable to true, and the other two variables to mouse_x / mouse_y. When first variable is true draw sprite7 at the position of the remaining two variables.

    Then when you want it "switched off" do something like:
    Code:
    if (MBR_selected)
    {
    if is_menu // a variable used so that the next bit of code is only done if the menu is open
    {
    if !is_right_button // the variable for recording the state of activation by mouse presses
    {
    is_x = mouse_x; // You probably won't want to use these, but without knowing anything else I can't figure out a more useful coordinate for you. Whatever way you're finding the skill they've clicked on, also get the x / y to use
    is_y = mouse_y; //  You probably won't want to use these, but without knowing anything else I can't figure out a more useful coordinate for you. Whatever way you're finding the skill they've clicked on, also get the x / y to use
    is_right_button = true;
    }
    else
    {
    is_right_button = false;
    }
    }
    }
    menu is activated:
    Code:
    is_menu = true;
    menu is not activated:
    Code:
    is_menu = false;
    draw:
    Code:
    if is_menu // only draws if menu is open
    {
    if is_right_button // only draws if skill has been selected
    {
    draw_sprite(sprite7, 0, is_x, is_y);}
    }
    }
    only draws if both is_menu is true (menu is currently active) and is_right_button is true (player clicked on a skill)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice