Sumbangan / Donate

Donate (Libery Reserve)


U5041526

Kamis, 22 Desember 2011

Game Maker Example - Font Changer

Nih satu lagi contoh untuk aplikasi yang dibuat dengan Game Maker 8.0.
Fungsinya untuk merubah font dan warna fontnya, cocok untuk aplikasi pengolah teks.

Berikut tutorialnya.

Install Extension GM Windows Dialogs, lihat gambar:











Buatlah sebuah object (nama object terserah Anda). Lalu pada Create event isi kode ini:

text = "By Kevin Blaze Coolerz" //text awalnya
color = c_black //warna awal yaitu hitam
new_font = font0 //jangan lupa untuk membuat font0

Lalu pada Step event. isi kode ini:

if keyboard_check_pressed(ord("Z")) //Jika tekan Z
{
if (wd_font_dialog_show()) { // Pengguna klik OK
name = wd_font_dialog_get_name(); //get font name
size = wd_font_dialog_get_size(); //get font size
bold = (wd_font_dialog_get_style() & wd_fs_bold) != 0; //jika stylenya bold
italic = (wd_font_dialog_get_style() & wd_fs_italic) != 0; //jika stylenya italic
//tidak bisa menggunakan font effect
new_font = font_add(name, size, bold, italic, 32, 126); // Termasuk semua karakter
}
}

if keyboard_check_pressed(ord("X")) //Jika tekan X
{
if (wd_color_dialog_show()) //Jika tekan cancel, warna textnya tidak berubah
{
color = wd_color_dialog_get_color()
}
}

//or you can use this metode

if keyboard_check_pressed(ord("C")) //Jika tekan C
{ // Kalau tekan Cancel, maka wanra text nya berubah jadi putih
color = get_color(c_black)
}

//change the text

if keyboard_check_pressed(vk_space) //if press Space
{
text = wd_input_box('Change text','Enter new text here','Kevin Blaze Coolerz')
//same as text = get_string('Enter the new text here:','Kevin Blaze Coolerz')
}

Pada Draw event, isi kode ini:

draw_set_font(new_font)
draw_set_color(color)
draw_text(20,20,string(text)+'##Press Z to change the Font#Press X or C to change the font color#Press Space to change the text')

Karena kita memakain font0 pada variabel new_font, maka kita harus membuat font dengan nama font0.

Setelah itu, tinggal masukan object dalam room dan play :)

Selamat mencoba...

File *.GMK nya bisa download DISINI

Tidak ada komentar:

Posting Komentar