This issue was posed on the Steam forums. The person in question wanted to know how to create text, even dynamically (say from a user input), and turn it into a sprite with physics, since the physics commands don't seem to work on text IDs. I enjoy a challenge and was bored, so I came up with a solution. I don't know if this is the
best solution, necessarily. I'm pretty new to this. Still, maybe it'll help someone else.
// create and display text
// display a background
w = 1280
h = 720
SetWindowSize( w, h, 0 )
SetVirtualResolution( w, h )
// create text
i_text = CreateText( "HELLO AGK!" )
SetTextSize( i_text, 40 )
i_textWidth = GetTextTotalWidth( i_text )
i_textHeight = GetTextTotalHeight( i_text )
Render()
// Capture text
i_tmp = GetImage( 0, 0, i_textWidth, i_textHeight )
SetImageTransparentColor( i_tmp, 0, 0, 0 )
ClearScreen()
// Create a background
i_back = CreateSprite ( CreateImageColor( 128, 0, 255, 255 ) )
SetSpriteSize( i_back, w, h )
// Create the sprite from the text
i_sprite = CreateSprite( i_tmp )
// Hide the text, can also delete
SetTextVisible( i_text, 0 )
i_spriteWidth = GetSpriteWidth( i_sprite )
i_spriteHeight = GetSpriteHeight( i_sprite )
// Give it physics
SetPhysicsMaxPolygonPoints( 12 )
SetSpritePhysicsOn( i_sprite, 2 )
SetSpriteShape( i_sprite, 3)
SetSpritePhysicsRestitution( i_sprite, 2 )
SetPhysicsDebugOn()
SetSpritePosition( i_sprite, w/2 - (i_spriteWidth/2), h/2 - (i_spriteHeight/2) )
do
// update the screen
Sync ( )
loop