Hello all,
Try as I might, I cannot get rid of the glitches which appear around pasted sprites, and it’s driving me INSANE!

I am half the man I was.
I’m writing a piece of code which produces a box of any size by building it up from blocks.
The code works, but as you can see in this pic:
There are glitches which appear around some of the pasted sprites – glitches which are not part of the image in the atlas. And to confound me more, these appear when the app is displayed at different sizes, and not others.
The app above looks fine in windowed mode, but if you click maximise, or set it to full screen, the glitches appear. Sometimes on the left or right-hand side, too.
I’ve tried messing with loads of different commands, and I am getting balder by the second. Would anyone mind having a look at this for me to see what I’m doing wrong? Media is attached.
// Set window and display. Try fullscreen for more glitches!
SetWindowTitle( "Glitch Central" )
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
// Set vars for size of box
fBoxX# = 20
fBoxWidth# = 295
fBoxY# = 20
fBoxHeight# = 198
// Load assets
iAtlasImage = LoadImage("Gfx.png")
iBackgroundImage = LoadSubImage(iAtlasImage,"Background")
iTopLeftImage = LoadSubImage(iAtlasImage,"TopLeft")
iTopRightImage = LoadSubImage(iAtlasImage,"TopRight")
iBottomLeftImage = LoadSubImage(iAtlasImage,"BottomLeft")
iBottomRightImage = LoadSubImage(iAtlasImage,"BottomRight")
iTopImage = LoadSubImage(iAtlasImage,"Top")
iLeftImage = LoadSubImage(iAtlasImage,"Left")
iRightImage = LoadSubImage(iAtlasImage,"Right")
iBottomImage = LoadSubImage(iAtlasImage,"Bottom")
iMiddleImage = LoadSubImage(iAtlasImage,"Middle")
// Create a sprite to use for the background
iBackgroundSprite = CreateSprite(iBackgroundImage)
// Create image which we will render the box onto
iBoxImage = CreateRenderImage(GetVirtualWidth(),GetVirtualHeight(),0,0)
// Create a sprite which we will use to paste the parts of the box onto the iBoxImage
iSpriteToPaste = CreateSprite(iTopLeftImage)
SetImageMagFilter(iSpriteToPaste,0)
SetSpriteTransparency(iSpriteToPaste,0)
SetSpriteUVBorder(iSpriteToPaste,1) // Trying ANYTHING here to get rid of the glitches!
// Begin rendering to the image
SetRenderToImage(iBoxImage,0)
SetVirtualResolution(GetDeviceWidth(),GetDeviceHeight())
ClearScreen()
iRowOn as integer = 0
iColumnOn as integer = 0
// Paste the top, left and middle pieces onto the render image.
do
if (iRowOn = 0)
if (iColumnOn = 0)
SetSpriteImage(iSpriteToPaste,iTopLeftImage)
else
SetSpriteImage(iSpriteToPaste,iTopImage)
endif
else
if (iColumnOn = 0)
SetSpriteImage(iSpriteToPaste,iLeftImage)
else
SetSpriteImage(iSpriteToPaste,iMiddleImage)
endif
endif
fXPosToPaste# = GetSpriteWidth(iSpriteToPaste) * iColumnOn
fYPosToPaste# = GetSpriteHeight(iSpriteToPaste) * iRowOn
SetSpritePosition(iSpriteToPaste,fXPosToPaste#,fYPosToPaste#)
DrawSprite(iSpriteToPaste)
// Have we pasted the last column?
if (fXPosToPaste# >= fBoxWidth#)
iColumnOn = 0
inc iRowOn
// Have we pasted the last row?
if (GetSpriteHeight(iSpriteToPaste) * iRowOn >= fBoxHeight#)
exit
endif
else
inc iColumnOn
endif
loop
// Paste the top-right piece on.
SetSpriteImage(iSpriteToPaste,iTopRightImage)
fXPosToPaste# = fBoxWidth# - GetSpriteWidth(iSpriteToPaste)
SetSpritePosition(iSpriteToPaste,fXPosToPaste#,0)
DrawSprite(iSpriteToPaste)
// Paste the right-hand pieces.
iRowOn = 1
SetSpriteImage(iSpriteToPaste,iRightImage)
do
fYPosToPaste# = GetSpriteHeight(iSpriteToPaste) * iRowOn
SetSpritePosition(iSpriteToPaste,fXPosToPaste#,fYPosToPaste#)
DrawSprite(iSpriteToPaste)
// Have we pasted the last one?
if (fYPosToPaste# >= fBoxHeight#)
exit
endif
inc iRowOn
loop
// Paste the bottom-left piece on.
SetSpriteImage(iSpriteToPaste,iBottomLeftImage)
fYPosToPaste# = fBoxHeight# - GetSpriteHeight(iSpriteToPaste)
SetSpritePosition(iSpriteToPaste,0,fYPosToPaste#)
DrawSprite(iSpriteToPaste)
// Paste the bottom pieces.
iColumnOn = 1
SetSpriteImage(iSpriteToPaste,iBottomImage)
do
fXPosToPaste# = GetSpriteWidth(iSpriteToPaste) * iColumnOn
SetSpritePosition(iSpriteToPaste,fXPosToPaste#,fYPosToPaste#)
DrawSprite(iSpriteToPaste)
// Have we pasted the last one?
if (fXPosToPaste# >= fBoxWidth#)
exit
endif
inc iColumnOn
loop
// Paste the bottom-Right piece on.
SetSpriteImage(iSpriteToPaste,iBottomRightImage)
fXPosToPaste# = fBoxWidth# - GetSpriteWidth(iSpriteToPaste)
fYPosToPaste# = fBoxHeight# - GetSpriteHeight(iSpriteToPaste)
SetSpritePosition(iSpriteToPaste,fXPosToPaste#,fYPosToPaste#)
DrawSprite(iSpriteToPaste)
// Finished the render. Back to rendering to the screen.
DeleteSprite(iSpriteToPaste)
SetRenderToScreen()
SetVirtualResolution(1024, 768)
// Create a sprite which will display the box.
iBoxSprite = CreateSprite(0)
SetSpriteSize(iBoxSprite,fBoxWidth#,fBoxHeight#)
SetSpriteImage(iBoxSprite,iBoxImage)
// Set the sprite's size and UV to display only the box we rendered.
fSpriteHoriz# = GetSpriteWidth(iBoxSprite) / GetImageWidth(iBoxImage)
fSpriteVert# = GetSpriteHeight(iBoxSprite) / GetImageHeight(iBoxImage)
SetSpriteUV(iBoxSprite, 0,0, 0,fSpriteVert#, fSpriteHoriz#,0, fSpriteHoriz#,fSpriteVert#)
SetSpriteUVBorder(iBoxSprite,1) // Trying ANYTHING here to get rid of the glitches!
SetImageMagFilter(iBoxSprite,0)
SetSpriteTransparency(iBoxSprite,1)
SetSpritePosition(iBoxSprite,fBoxX#,fBoxY#)
do
sync()
loop
Thanks in advance,
James