Just for kicks, I recreated the digits from the OP as a bitmap font, using a texture atlas that is HALF (128x64) the size of the original (128x128), but contains the same digits at the original resolution - while also including a space, colon, and the period.
It was a fun little test... Here's the code snippet:
// Setup display
SetVirtualResolution( 480, 480 )
Setsyncrate(60,0)
// Define types
type TTextIDs
FPS as integer
Time as integer
endtype
// Declare global variables
global g_DigitAtlasID as integer
global g_TextID as TTextIDs
// Load bitmap font (the atlas is 128 by 64 pixels)
g_DigitAtlasID = LoadImage("numbers_v2.png")
// Note: the subimages.txt file is loaded automatically
// Create empty text objects for later use
g_TextID.FPS = CreateText( "" )
g_TextID.Time = CreateText( "" )
// Text object setup
SetTextFontImage(g_TextID.FPS, g_DigitAtlasID)
SetTextFontImage(g_TextID.Time, g_DigitAtlasID)
SetTextSize(g_TextID.FPS, 30)
SetTextSize(g_TextID.Time, 30)
SetTextPosition( g_TextID.FPS, 100, 100 )
SetTextPosition( g_TextID.Time, 100, 140 )
// Main loop
do
// Set FPS string
SetTextString(g_TextID.FPS, str(screenfps()))
// Set time string
SetTextString(g_TextID.Time, GetCurrentTime())
// Update display
Sync()
// Exit on pointer press
if GetPointerPressed() then exit
loop
And here's the new font bitmap:
The following post contains a package with the full project in ready to compile form (tested with AppGameKit 1076).
By using text objects instead of individual sprites, we gain the following advantages:
* We can add as many, or as few, characters in the bitmap font as we like, and they will be handled automatically with no extra code.
* With a single call to SetTextSize, SetTextSpacing, etc, we can change the appearance of the entire text object.
* Bitmap fonts can be created to utilize either variable width or fixed width letters/digits - with no changes in code; only the font bitmap definition (subimages.txt) needs to change.
* All of the low-level overhead of creating, showing, positioning and hiding individual letters is handled automatically by the text object.
But as there are always exceptions, the method that uses individual sprites would be better in some cases. It would certainly be better when advanced text animation is required -- such as non-linear motion (for example, when digits need to shoot from the sides, rain from the top, or spiral down into view or out of the view, etc.)
Cheers,
AgentSam
EDIT:
As per the documentation page here:
SetTextDefaultFontImage, I have noticed that the subimages.txt file does not need to list ALL characters, when only a subset is required. So it could be trimmed down quite a bit, when only the digits are required. (But the project link below contains the untrimmed version.)
Here's the relevant piece of information from the doc page: "The AppGameKit will look for images "32" up to and including "127" in the subimages file and any not found will default to the space character (32). "