phoboslab / Impact

HTML5 Game Engine
MIT License
1.99k stars 204 forks source link

Impossible to make multiple instances of ig.Font that share common image path #68

Open Joncom opened 4 years ago

Joncom commented 4 years ago

Say, for example, you wanted to create two instances of ig.Font, both which share the same image: 'media/04b03.font.png'

MyGame = ig.Game.extend({

    font1: new ig.Font( 'media/04b03.font.png' ),
    font2: new ig.Font( 'media/04b03.font.png' ),

    draw: function() {
        this.parent();

        var x = ig.system.width/2,
            y = ig.system.height/2;

        this.font1.draw( 'It Works 1!', x, y, ig.Font.ALIGN.CENTER );
        this.font2.draw( 'It Works 2!', x, y + 10, ig.Font.ALIGN.CENTER );
    }
});

download

Then let's say you want to modify the letter spacing of one, but not the other...

Sep-15-2019 01-01-49

It's not possible. Modifying one font instance, modifies the other, because they are the same instance. You can't have more instances, due to the way ig.Image caching works.

This works great for images, but not necessarily for fonts.

Perhaps it would make sense for ig.Font to be its own class, and simply have an image property which it reads from, instead of extending from ig.Image.