View Full Version: "if hiiri_on_tekstin_päällä"

Game Maker Suomi > Koodinpätkät > "if hiiri_on_tekstin_päällä"


Title: "if hiiri_on_tekstin_päällä"
Description: Vaihtaa myös väriä


Onion King - October 15, 2005 09:24 PM (GMT)
CODE
{
 //argument0 = tekstin x-sijainti
 //argument1 = tekstin y-sijainti
 //argument2 = teksti
 //argument3 = tekstin mouse-off väri
 //argument4 = tekstin mouse-on väri
 var tx_x,tx_y,tx_str,tx_w,tx_h,on;
 tx_x = argument0;
 tx_y = argument1;
 tx_str = argument2;
 tx_w = string_width(tx_str);
 tx_h = string_height(tx_str);
 on = (mouse_x > tx_x and mouse_x < tx_x + tx_w and mouse_y > tx_y and
 mouse_y < tx_y + tx_h);
 font_color = argument3;
 if on = 1
  {
   font_color = argument4;
  }
 draw_text(tx_x,tx_y,tx_str);
 return on;
}

Tätä koodia voi käyttää vaikka tekstinappina. Esimerkiksi jos haluat, että peli loppuu kun painat "Exit"-tekstiä ja samalla teksti muuttuu valkoiseksi, tee näin:
CODE
{
 if text_on(16,16,"Exit",c_black,c_white) and mouse_check_button(mb_left)
  {
   game_end();
  }
}

Ei tarvitse antaa creditsejä.




* Hosted for free by InvisionFree