Here is another version of my smooth conveyour:
- optimized for speed
- videos are now supported
Read my previous post for details
const tilesCount = 5 //keep it odd number
const tilesOffscreen = 3
const tileWidth = 300
const tilePadding = 8
const tileKeepAspect = false
const surfacePosSmoothing = 0.85
local videoFlags = Vid.ImagesOnly // Vid.NoAudio for videos
local flw = fe.layout.width;
local flh = fe.layout.height;
local tilesTable = []
local tilesTableOffset = 0
local tilesTotal = tilesCount + tilesOffscreen * 2
local tileHeight = flh / tilesCount
local surfaceWidth = tileWidth + 4 // frame.png is 304x220
local surfaceHeight = tilesTotal * tileHeight
local surfacePosY = 0
local surfacePosYOffset = tilesOffscreen * tileHeight
local surface = fe.add_surface( surfaceWidth, surfaceHeight )
local index = -floor( tilesTotal / 2 )
for( local i = 0; i < tilesTotal; i++ ) {
local obj = surface.add_artwork( "snap" )
obj.set_pos( 2, tileHeight * i + ( tilePadding / 2 ), tileWidth, tileHeight - tilePadding )
obj.preserve_aspect_ratio = tileKeepAspect
obj.index_offset = index
obj.video_flags = videoFlags
tilesTable.push( obj )
index++
}
local frame = surface.add_image( "frame.png", 0, tilesTotal / 2 * tileHeight - 10, 304, tileHeight + 20 )
fe.add_transition_callback( this, "on_transition" )
function on_transition( ttype, var, ttime ) {
if ( ttype == Transition.ToNewSelection ) {
local index = -floor( tilesTotal / 2 )
tilesTableOffset += var
for ( local i = 0; i < tilesTable.len(); i++ ) {
local indexTemp = wrap( i + tilesTableOffset, tilesTable.len() )
tilesTable[ indexTemp ].rawset_index_offset( index );
tilesTable[ indexTemp ].y = i * tileHeight + tilePadding / 2
index++
}
surfacePosY += var * tileHeight
}
}
fe.add_ticks_callback( "tick" )
function tick( tick_time ) {
surfacePosY = surfacePosY * surfacePosSmoothing
if ( surfacePosY > surfacePosYOffset) surfacePosY = surfacePosYOffset
if ( surfacePosY < -surfacePosYOffset) surfacePosY = -surfacePosYOffset
surface.set_pos( 200, surfacePosY - surfacePosYOffset )
}
// wrap around value witin range 0 - N
function wrap( i, N ) {
while ( i < 0 ) { i += N }
while ( i >= N ) { i -= N }
return i
}