As some of you probably know drawing something on nested surfaces in AM introduces an unwanted artifact, a 1 or more frames of delay in updating the nested surface content.
Luckily I discovered a neat trick that circumvents that.
Here is a code example that draws a game title twice in white colour, and twice in black but on nested surfaces ( with a little offset to make you see the white text underneath )
Just scroll through your game list and observe that the left side is blinking in white, that's the delay I'm referring to as the black title on a nested surface is being drawn with 1 frame delay.
The text on the right is drawn without any delay.
// This is an example of how to draw nested surfaces and avoid 1 frame delay ( or more, depending on the nesting level )
// The text on the left is blinking as the white text drawn on fe is updated first,
// then the black text on a surface is drawn on top, but it's late by 1 frame
// On the right the white and black texts are drawn on the same frame
local flw = fe.layout.width
local flh = fe.layout.height
local background = fe.add_text( "", 0, 0, flw, flh )
background.set_bg_rgb( 50, 150, 150 )
// title drawn on fe. in white
local textOnFe1 = fe.add_text( "[Title]", 0, 0, flw/2, 50 )
textOnFe1.align = Align.Left
// title drawn on fe. in white
local textOnFe2 = fe.add_text( "[Title]", flw/2, 0, flw/2, 50 )
textOnFe2.align = Align.Left
// SURFACE WITHOUT DELAY ( on the right )
local nestedSurface2 = fe.add_surface( flw/2, 50 )
// title drawn on nested surface in black
local txtsu2 = nestedSurface2.add_text( "[Title]", 0, 0, flw/2, 50 )
txtsu2.align = Align.Left
txtsu2.set_rgb( 0, 0, 0 )
// main surface on which both nested surfaces are drawn
local mainSurface = fe.add_surface( flw, 50 )
// shift the main surface by 2 pixes so you can see the white text underneath
mainSurface.set_pos( 0, 1 )
/////////////////////////////////////
// THE LINES BELOW ARE THE TRICK
nestedSurface2.visible = false
nestedSurface2 = mainSurface.add_clone( nestedSurface2 )
nestedSurface2.visible = true
/////////////////////////////////////
// position nested surface to the right
nestedSurface2.set_pos( flw/2, 0 )
// SURFACE WITH DELAY ( on the left )
local nestedSurface1 = mainSurface.add_surface( flw/2, 50 )
// title drawn on nested surface in black
local txtsu1 = nestedSurface1.add_text( "[Title]", 0, 0, flw/2, 50 )
txtsu1.align = Align.Left
txtsu1.set_rgb( 0, 0, 0 )
// do something at tick() so the screen keeps updating
function tick(ttime) {
mainSurface.x = 0
}
fe.add_ticks_callback( "tick" )