Pardon the mess, Play My Code is in beta!

READY TO PLAY?
CLICK TO LOG IN!

sign up - lost password

setFont

setFont allows you to permanently change the font used when drawing text. Unlike setColor and the rotations, the font is not reset on each frame.

If the font name is not found, then the browser will automatically default back to the system font.

Note that different browsers, and operating systems, will each render the font differently.

setFont( name, size )

Sets the font to use when drawing text. 'font' should be the name of the font, whilst 'size' refers to it's height in pixels.

setFont( 'Impact', 60 )

onEachFrame() do |delta|
    fill( :black )
    
    fillText( "This is in IMPACT!", getScreenWidth()/2, getScreenHeight()/2, true )
end

setFont( name, size ) { ... }

The block version of setFont. This will only alter the font for the lifetime of the block, and set it back to the previous font when the block returns.

fonts = [
        'Arial', 'Impact', 'Segoe UI',
        'Comic Sans MS', 'Times New Roman',
        'Courier New', 'Lucidia Console',
        'Tahoma', 'Verdana',
        'Georgia', 'Trebuchet MS'
]
fontSize = 21

onEachFrame() do |delta|
    fill( :black )
    
    fonts.eachMapping() do |i, font|
        setFont( font, fontSize )
        
        fillText(
                "The quick brown fox jumped over the lazy dog",
                10, 10 + i*fontSize*1.1,
                :left, :top
        )
    end
end

setFont( name, size, style )

Sets the font to use, but also allows you to specify a style.

Styles should be supplied as a string which includes all of the styles to use. This currently only allows 'bold', 'italic', or 'bold italic'.

setFont( 'Impact', 48, 'Italic' )

onEachFrame() do |delta|
    fill( :black )
    
    fillText( "This is in IMPACT! (italic)", getScreenWidth()/2, getScreenHeight()/2, true )
end

setFont( name, size, style ) { ... }

The same as the previous setFont, only this localizes the change to just the block.

See Also