so that you can change the texture of the clouds, you need to always have the same texture size or change the size of the sprite before loading a new texture into it.
try not to use gosub in large projects this may cause no convenience.
See how it works and use
ScreenToWorldX() to convert coordinates or
GetViewOffsetX()
global cloud_image as integer[]
for i=1 to 5
cloud_image.insert(loadimage("clouds"+str(i)+".png"))
next
type cloud_class
id as integer
speed as integer
endtype
global cloud as cloud_class [5]
//-------------------------------------------------------------
for i=0 to cloud.length
cloud[i].id=CreateSprite(cloud_image[random(0,cloud_image.length)])
cloud[i].speed=random(1,5)
SetSpritePosition(cloud[i].id, random(0, GetVirtualWidth()), random(0, GetVirtualHeight()-GetSpriteHeight(cloud[i].id)))
next i
//-------------------------------------------------------------
function CloudMove()
for i=0 to cloud.length
SetSpritePosition(cloud[i].id, GetSpriteX(cloud[i].id)-cloud[i].speed, GetSpriteY(cloud[i].id) )
if GetSpriteX(cloud[i].id) < GetViewOffsetX()-GetSpriteWidth(cloud[i].id)
image_id = random(0,cloud_image.length)
SetSpriteSize(cloud[i].id, GetImageWidth(cloud_image[image_id]), GetImageHeight(cloud_image[image_id]) )
SetSpriteImage(cloud[i].id, cloud_image[image_id])
SetSpritePosition(cloud[i].id, GetVirtualWidth()+GetViewOffsetX(), random(0, GetVirtualHeight()-GetSpriteHeight(cloud[i].id)) )
endif
next i
endfunction
//-------------------------------------------------------------
SetViewOffset(500, 0)
do
CloudMove()
sync()
loop