Spritefont Text Generator
Versi: 1.0 (WIP)
Tipe: Custom Text Drawing System
PengenalanScript ini digunakan untuk menampilkan teks dengan menggunakan sprite yg disebut Spritefont, tidak dengan font2 yg terinstal di komputer. Sistem ini banyak digunakan di beberapa game konsol (Sega, PS, DOS games, dll) dan bahkan game2 kecilan yg sekarang juga menggunakan ini.
Dengan sistem ini, anda dapat membuat dan menggunakan style tulisan sendiri tanpa harus membuat file font dan menginstalnya di komputer, hanya dengan mengedit spritefont di image editor anda (Paint, Photoshop, etc).
Berikut ini contoh spritefont:
Features To-Do List- Text alignment (left, center, right) [DONE]
- Multiline text [N/A]
- Word wrap text [N/A]
- Characters with non-uniform widths. [N/A]
- Meng-override bagian2 script default RGSS yang menampilkan teks2 di menu dan dialog dengan sistem spritefont [N/A]
FAQQ: Apa itu spritefont?
A: Sprite yang berisi tile2 karakter teks, seperti yg ditunjukkan di contoh di atas.
Q: Gimana cara masang scriptnya?
A: Tinggal lgs copas di slot script yg baru.
Q: Gimana cara menggunakannya?
A: Lihat petunjuk di script-nya dan pelajari demo-nya.
Q: Saat pindah scene, koq teksnya tetep ada?
A: Berarti anda lupa panggil method dispose setelah Graphics.freeze ato bagian dispose scene-nya
Q: Kenapa script ini masih WIP?
A: Belum semua fitur di To-do List diimplementasikan disini.
Q: Koq huruf2 yg ditampilkan ga sesuai?
A: Berarti penyusunan karakter2 di spritefont anda ada yg salah. Susunannya harus sesuai urutan kode ASCII, mulai dari kode 33 ('!') sampai 176. Atau biar ga bingung, lihat di contoh spritefont.
Q: Ukuran gambar spritefont bebas ga?
A: Ya, tapi panjangnya hrs kelipatan 16 dan lebarnya hrs kelipatan 9.
Q: Bisakah script ini digunakan di RMVX?
A: Ya, karena scriptnya tidak memanipulasi script2 default. Tapi penggunaannya mungkin sedikit berbeda.
Screenshot
DemoSample untuk menampilkan teks2 di scene baru (pake RMXP). Disini navigasi New Game tidak ke Scene_Map, tapi justru ke scene baru tsb.
http://ifile.it/98voxpq/spritefont.zip
Script - Code:
-
#==============================================================================
# Spritefont Text Generator (WIP)
# Version 1.01
#==============================================================================
# Copyrighted by Bunga Tepi Jalan.
# * Don't forget to credit me if you want to use this work
# * You are free to Share - to copy, distribute and transmit the work
# * You are free to Remix - to adapt the work
# * You may not use this work for commercial purposes
#
#==============================================================================
# Information:
# This script enables you to draw text using a sprite, called spritefont,
# without having to use fonts installed on your computer.
#
# Usage Notes
# - Place spritefont files at location as configured in this script.
# - Each spritefont file contains 16x9 character tiles, so its width and
# height must be divisible by 16 and 9, respectively (e.g. 144x108).
# - Character tiles are ordered by ASCII code of the characters,
# beginning from code 33 to 176.
# - Don't forget to call update method after changing the text position.
# - Don't forget also to call dispose method in the end of current scene.
#
# If you find any bugs or you have any suggestions, please report them via
# e-mail (listra92@gmail.com), or either my blog or these forums:
# - http://bungatepijalan.wordpress.com
# - http://rmid.forumotion.net
#==============================================================================
module Spritefonts
#--------------------------------------------------------------------------
# * Spritefont Text Generator Configuration
#--------------------------------------------------------------------------
# Location of spritefont files to be used
SF_PATH = "Graphics/Pictures/spritefonts/"
#==============================================================================
# ** SFText
#------------------------------------------------------------------------------
# An instance of this class represents a text drawn on the screen. Use
# Spritefonts::SFText.new(...) to create a new one.
#==============================================================================
class SFText
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :x
attr_accessor :y
attr_reader :text
attr_reader :align
#--------------------------------------------------------------------------
# * Object Initialization
# sfname : spritefont file name (without path)
# _text : text string
# _x, _y : position of text
# _align : text alignment (0: left, 1: center, 2: right)
#--------------------------------------------------------------------------
def initialize(sfname, _text, _x = 0, _y = 0, _align = 0)
@x = _x
@y = _y
@text = _text
@align = _align
@sfb = Bitmap.new(SF_PATH+sfname)
@chars = Array.new
update
end
#--------------------------------------------------------------------------
# * Change Text
# _text : new text string
#--------------------------------------------------------------------------
def change_text(_text)
@text = _text
update
end
#--------------------------------------------------------------------------
# * Change Align
# _align : text alignment (0: left, 1: center, 2: right)
#--------------------------------------------------------------------------
def change_align(_align)
@align = _align
update
end
#--------------------------------------------------------------------------
# * Update Text Display
#--------------------------------------------------------------------------
def update
cw = @sfb.rect.width/16
ch = @sfb.rect.height/9
if @chars.length != 0
dispose
@chars = Array.new
end
for i in 0..@text.length-1
@chars.push(Sprite.new(Viewport.new(x+cw*i, y, cw, ch)))
@chars[i].bitmap = @sfb
@chars[i].x = -((@text[i]-1)%16)*cw
@chars[i].y = -((@text[i]-1)/16-2)*ch
if @align == 1
@chars[i].viewport.rect.x -= cw*@text.length/2
elsif @align == 2
@chars[i].viewport.rect.x -= cw*@text.length
end
end
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
for i in 0..@chars.length-1
@chars[i].dispose
end
end
end
end
Credits