Giter Club home page Giter Club logo

haxe-format-bmfont's Introduction

haxe-format-bmfont

Reader for various kinds of bitmapfont files.

supported file formats

usage with rendering example

(Doesn't do any fancy stuff like kerning etc...)

package;

import format.bmfont.types.BitmapFont;
import format.bmfont.XmlReader;
import kha.graphics2.Graphics;

using Main.G2BitmapFontExtension;

class G2BitmapFontExtension {
    public static function drawBMFString( g: Graphics, font: BitmapFont, pages: Array<kha.Image>, x, y, text: String )
        for (i in 0...text.length) {
            var cc = text.charCodeAt(i);
            var char = font.chars.get(cc);

            g.drawSubImage(
                pages[char.pageId],
                x + char.xOffset, y + char.yOffset,
                char.x, char.y, char.width, char.height
            );

            x += char.xAdvance;
        }
}

class Main {
    public static function main()
        kha.System.start({}, function( _ ) kha.Assets.loadEverything(init));

    static function init()
        var fnt = XmlReader.read(Xml.parse(kha.Assets.blobs.SomeFont_fnt.toString());
        var pages = [kha.Assets.images.SomeFont_0];
        
        kha.System.notifyOnFrames(function( fbs ) {
            var fb = fbs[0];
            var g2 = fb.g2;

            g2.begin();
                g2.drawBMFString(fnt, pages, 16, 16, 'hello bmfont world!');
            g2.end();
        });
}

haxe-format-bmfont's People

Contributors

sh-dave avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.