Blitz3D+ Command Reference

Text x,y,text$[,centre_x][,centre_y]

Parameters

x - x coordinate to draw the text at

y - y coordinate to draw the text at

text$ - the text to draw

centre_x (optional) - 1 centres the text horizontally on x; 0 left-aligns (default)

centre_y (optional) - 1 centres the text vertically on y; 0 top-aligns (default)

Description

Draws text at a position on the current buffer.

This is the text command for games: unlike Print, you say exactly where the text goes, and it lands on the current buffer so it works inside the usual back-buffer/Flip loop. Scores, timers, dialogue, debug read-outs - Text x,y,"Score: "+score covers them all, converting numbers with the + concatenation as it goes.

By default x,y is the top-left corner of the text. Pass 1 for centre_x and/or centre_y to centre it on the point instead - perfect for titles and labels: Text GraphicsWidth()/2,y,"GAME OVER",1.

It draws in the current Color and the current font (see SetFont), respects Origin and clips to the Viewport. To measure text for layout, use StringWidth and StringHeight.

See also: Print, SetFont, StringWidth, StringHeight, Color.

Example

; Text Example
; ------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

score=0
x#=0

While Not KeyDown(1)

    Cls

    ; A drifting pickup so the HUD has a game to sit on
    x=x+3
    If x>640 Then x=-30
    Color 255,220,0
    Oval x,240,24,24,1

    ; Space scores points
    If KeyHit(57) Then score=score+100

    Color 255,255,255

    ; Text draws a string at any pixel position - the HUD workhorse
    Text 0,0,"Space: score points   Esc: exit"
    Text 0,20,"SCORE "+score

    ; The optional flags centre the string on the coordinates
    Text 320,460,"This line is centred with Text 320,460,txt$,True,True",True,True

    Flip

Wend

End

Index