just a small Lib to use Webfonts with Monkey.
var webFont = '';
var webFontSize = '12px';
var webFontColor = 'rgba(2455, 255, 255, 1.0)';
function LoadWebFont(source, fontname, size){
if(typeof fontname == 'string' && typeof size == 'number'){
var style = document.createElement('style');
var font = 'http://fonts.googleapis.com/css?family=' + source;
var css = document.createTextNode('@import url(' + font + ')');
webFont = fontname;
webFontSize = size + 'px';
style.appendChild(css);
document.getElementsByTagName('head')[0].appendChild(style);
}
};
function Text(txt, x, y, style){
game_canvas.getContext('2d').font = style + ' ' + webFontSize + ' ' + webFont;
game_canvas.getContext('2d').fillText(txt, x, y);
};
Module:
Import "native/utils.js"
Extern
Function LoadWebFont(source:String, fontname:String, size:Int) = "LoadWebFont"
Function Text(txt:String, x:Int = 0, y:Int = 0, style:String = "normal") = "Text"
Public
use it:
Method OnCreate:Int()
LoadWebFont("Inconsolata:400,700;", "Inconsolata", 18)
SetUpdateRate(30)
Return 0
End
Method OnUpdate:Int()
Return 0
End
Method OnRender:Int()
Cls()
Text("Hello World", 10, 20, "700 italic")
Return 0
End
have fun...
|