The way that the sprite position is calculated in Supertino's gap code example can also introduce gaps in both sets of images because of floating point rounding.
When the sprites are first positioned, their X is set to x * tile_size.
After that, "dist" is a subtraction of two floats and then each sprite is moved by adding "dist" to its current X. This is where rounding errors is introduced: each addition is adding to the rounded result of the previous addition which can cause a column to be off by a bit occasionally. When the window size and virtual size are multiples of the tile size this might be less obvious.
To be smooth, there needs to be a base value from which all other sprite locations are calculated. GetTweenCustomFloat1(move_x_tween) is already the X for the left tiles, so just use it as the base.
I've modified Supertino's example. I've changed the virtual width to 475 and made the bottom row sprites base their position on the tween's actual value. I get a gap in the top two rows of the top and bottom tile sets at around 50.145. The bottom row is fine because the rounding errors are not being compounded.
#option_explicit
// -----------------------------------------------------------------------------
// Settings
// -----------------------------------------------------------------------------
filter as integer
filter = 0 // 0 = pixel (nearest), 1 = blurry (linear)
// -----------------------------------------------------------------------------
// set window properties
SetWindowTitle( "gaps, what gaps?" )
SetWindowSize( 1200, 600, 0 )
SetWindowAllowResize( 1 )
SetPrintSize(14)
// set display properties
SetVirtualResolution( 475, 240 )
SetSyncRate( 60, 1 )
UseNewDefaultFonts( 1 )
SetClearColor(255,0,255)
// Misc
tile_size as float
tile_size = 40
dist as Float // For tween
// Store tiles (sprites)
tiles_no_extrude as Integer[9]
tiles_extruded as Integer[9]
// Load atlas images
atlas_no_extrude as integer
atlas_extruded as integer
atlas_no_extrude = LoadImage("no_extrude.png")
atlas_extruded = LoadImage("extruded.png")
// Image filter
SetImageMagFilter(atlas_no_extrude, filter)
SetImageMinFilter(atlas_no_extrude, filter)
SetImageMagFilter(atlas_extruded, filter)
SetImageMinFilter(atlas_extruded, filter)
// Load sprites from atlas images
i as integer
For i = 0 To 8
tiles_extruded[i] = CreateSprite(LoadSubImage(atlas_extruded, Str(i)+".png"))
tiles_no_extrude[i] = CreateSprite(LoadSubImage(atlas_no_extrude, Str(i)+".png"))
Next i
// Position tiles
x as integer
y as integer
i = 0
For y = 0 to 2
For x = 0 to 2
SetSpritePosition(tiles_no_extrude[i], x * tile_size , y * tile_size)
SetSpritePosition(tiles_extruded[i], x * tile_size , (y * tile_size) + (GetVirtualHeight()/2))
Inc i
Next x
Next y
// Create a tween to move tiles
move_x_tween as integer
//~ move_x_tween = CreateTweenCustom(7)
//~ SetTweenCustomFloat1(move_x_tween, 0, GetVirtualWidth() - (tile_size*3), TweenSmooth2())
move_x_tween = CreateTweenCustom(8)
SetTweenCustomFloat1(move_x_tween, 50.12, 50.16, TweenLinear())
PlayTweenCustom(move_x_tween, 0)
tweenx as float
// Main Loop
do
// Update tween
UpdateTweenCustom(move_x_tween, GetFrameTime())
// Move sprites - Supertino's code (top two rows)
dist = GetTweenCustomFloat1(move_x_tween) - dist
For i = 0 To 6
SetSpriteX(tiles_no_extrude[i], GetSpriteX(tiles_no_extrude[i]) + dist)
SetSpriteX(tiles_extruded[i], GetSpriteX(tiles_extruded[i]) + dist)
Next i
dist = GetTweenCustomFloat1(move_x_tween)
// Move bottom row sprites, calculating based on tween's value.
tweenx = GetTweenCustomFloat1(move_x_tween)
For i = 0 to 2
SetSpriteX(tiles_no_extrude[6 + i], tweenx + i * tile_size)
SetSpriteX(tiles_extruded[6 + i], tweenx + i * tile_size)
Next
// Reset Tween when it ends
If Not GetTweenCustomPlaying(move_x_tween) Then PlayTweenCustom(move_x_tween, 0)
// Prints
Print( " no extrude - some might see small gaps between" )
Print( "" ) : Print( "" ) : Print( "" ) : Print( "" ) : Print( str(tweenx) ) : Print( "" ) : Print( "" ) : Print( "" )
Print( " extruded - should elimate the gaps" )
DrawLine(0, GetVirtualHeight()/2, GetVirtualWidth(), GetVirtualHeight()/2, 0 ,0)
Sync()
loop
This particular code is gapless for me no matter which filter is used.