Jump to content

Font, loading & letterSpacing Sample


tricksty77
 Share

Recommended Posts

I had build a font with BMFont which was loaded properly in panda but when I converted the xml in json I had problem in the Font Contructor

I had the needs to change the text.js in the engine in order to make this works (the json file was not loaded properly)

1955449317_2018-07-1810_50_57-C__Users_s.peranzoni_Documents_GitHub_Panda_font_src_engine_renderer_text.js-N.thumb.png.3ee4af412720a295a4439a081f27917e.png

 

I would like to share with you a sample I have done (I think other people will find useful if is moved into the panda examples)

 

game.module(
    'game.main'
)
.body(function() {


game.addAsset('test1_0.png');
game.addAsset('example.json');

game.createScene('Main', {
        init: function() {
            this.text = new game.Text('Hello Panda!');
            this.text.addTo(this.stage);
            this.json = game.getJSON('example.json');
            
            this.font = new game.Font(this.json);
            this.font.letterSpacing = 1;
            this.text.fontClass = this.font;
            this.text.updateText();
        },
        
        mousedown: function() {
            this.font.letterSpacing = 10;
            this.text.updateText();
            
        },
    
        mouseup: function() {
            this.font.letterSpacing = 1;
            this.text.updateText();
        }
    });
});

 

P S: I also want to signal that this very same segment of text.js code will not works if the font is splitted in multiple bitmap so pay attention to that when you export fonts from BMFont. (try to squeeze all chars into a single png)

 

 

media.zip

Link to comment
Share on other sites

Currently Panda supports bitmap fonts in XML and BMFont formats (with fnt file extension). Is there any reason why you want to load your font in json?

I'm not sure what you are trying to do in your example, but i think you are making things a bit too complicated. If you just want to dynamically change the letter spacing of a text, it would be just simple as this:

game.addAsset('font.fnt');

game.createScene('Main', {
    init: function() {
        this.text = new game.Text('Hello Panda!');
        this.text.addTo(this.stage);
    },
    
    mousedown: function() {
        this.text.fontClass.letterSpacing = 10;
        this.text.updateText();
    },
    
    mouseup: function() {
        this.text.fontClass.letterSpacing = 1;
        this.text.updateText();
    }
});

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...