Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Hareesun

I know this may sound kinda silly, but is there anyway to make one item exempt from the system.scale?

I'm putting together quite a minimalist style game and using the scale to make the sprites four times their size. But the fonts at four times a good size stop being quite so legible.

I realise I could just scale up all the graphics and have the scale at the size I want the font. But you know...

If not, such a feature/method would be handy for future releases :)

1 decade ago by dominic

You could subclass ig.Font and overwrite the resize() method with an empty function. You&039;d also need to overwrite the #_drawChar() method to ignore the ig.system.scale. Something like this should work (untested):

ig.UnscaledFont = ig.Font.extend({
	resize: function(){ /* Do nothing */ },

	_drawChar: function( c, targetX, targetY ) {
		if( !this.loaded || c < 0 || c >= this.indices.length ) { return 0; }
		
		var charX = this.indices[c] * scale;
		var charY = 0;
		var charWidth = this.widthMap[c];
		var charHeight = (this.height-2);
		
		ig.system.context.drawImage( 
			this.data,
			charX, charY,
			charWidth, charHeight,
			ig.system.getDrawPos(targetX), ig.system.getDrawPos(targetY),
			charWidth, charHeight
		);
		
		return this.widthMap[c] + 1;
	}
});

1 decade ago by Hareesun

I can see how that would work, but for some reason I couldn't get it to. Forever getting a parsing error or crazily aligned letters.

Thanks though :)

1 decade ago by dominic

Sorry, I should&039;ve tested it before. I forgot to take out one #* scale and the function needs to return the unscaled width of the character.

This time it works, I promise :)

ig.UnscaledFont = ig.Font.extend({
    resize: function(){ /* Do nothing */ },

    _drawChar: function( c, targetX, targetY ) {
        if( !this.loaded || c < 0 || c >= this.indices.length ) { return 0; }
        
        var charX = this.indices[c];
        var charY = 0;
        var charWidth = this.widthMap[c];
        var charHeight = (this.height-2);
        
        ig.system.context.drawImage( 
            this.data,
            charX, charY,
            charWidth, charHeight,
            ig.system.getDrawPos(targetX), ig.system.getDrawPos(targetY),
            charWidth, charHeight
        );
        
        return this.widthMap[c] / ig.system.scale + 1;
    }
});

1 decade ago by Hareesun

Dominic, you're a genius. Once again to the rescue. :) Thanks so much!
Page 1 of 1
« first « previous next › last »