@luxuluxu
Here's a little something to get you started. This works best with imagefonts, not so good with standard fonts.
// Project: OutlinedFont
// Created: 22-05-21
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "OutlinedFont" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
global font as integer
font = LoadImage("GraffitiFont.png")
do
PutTextAt("Outlined Text Example", font, 75, 350, 38, 58, 00, 100, 0, 0, 200, 0)
Sync()
loop
function PutTextAt(textString as string, fontID as integer, x as float, y as float, size as float, outlineSize as float,
r as integer, g as integer, b as integer, bR as integer, bG as integer, bB as integer)
local outlineText as integer
local text as integer
local charTemp as integer
local outlineCharWidth as float
local charWidth as float
local outlineCharHeight as float
local charHeight as float
local textLength as integer
textLength = len(textString)
if not GetTextExists(text) or not GetTextExists(outlineText)
text = CreateText(textString)
outlineText = CreateText(textString)
SetTextFontImage(outlineText, fontID)
SetTextSize(outlineText, outlineSize)
SetTextColor(outlineText, bR, bG, bB, 255)
SetTextPosition(outlineText, x, y)
SetTextFontImage(text, fontID)
SetTextSize(text, size)
SetTextColor(text, r, g, b, 255)
SetTextPosition(text, x, y)
for i = 0 to textLength - 1
// Get width and height of outline char
charTemp = CreateText(mid(textString, i + 1, 1))
SetTextFontImage(charTemp, font)
SetTextSize(charTemp, outlineSize)
outlineCharWidth = GetTextTotalWidth(charTemp)
outlineCharHeight = GetTextTotalHeight(charTemp)
DeleteText(charTemp)
// Get width and height of foreground char
charTemp = CreateText(mid(textString, i + 1, 1))
SetTextFontImage(charTemp, font)
SetTextSize(charTemp, size)
charWidth = GetTextTotalWidth(charTemp)
charHeight = GetTextTotalHeight(charTemp)
DeleteText(charTemp)
SetTextCharX(text, i, GetTextCharX(outlineText, i) + ((outlineCharWidth - charWidth) / 2))
SetTextCharY(text, i, GetTextCharY(outlineText, i) + ((outlineCharHeight - charHeight) / 2))
next i
endif
DrawText(outlineText)
DrawText(text)
DeleteText(text)
DeleteText(outlineText)
endfunction