slide show

Hi All,

I used the following code to show a stack of images one after each other.

local function slideShow(delayTime, imageFNs)  
 local previousImageShow = system.getTimer();  
 local imIdx=0;  
 repeat  
 if system.getTimer()-previousImageShow\>delayTime then  
 if finishImage then  
 finishImage.fade=1;  
 end  
 imIdx = imIdx+1;  
 local imageFN = imageFNs[imIdx]  
 print(" Reading Image "..imageFN)  
 local finishImage = display.newImage(imageFN);  
 finishImage.x=D\_W/2  
 finishImage.y=D\_H/2  
 finishImage:scale(D\_W/finishImage.contentWidth,D\_H/finishImage.contentHeight)  
 zeroLayer:insert(finishImage)  
 transition.to(finishImage, {time=delayTime, alpha=0, onComplete=  
 function(self) display.remove(self); self = nil; end})  
 previousImageShow = system.getTimer()  
 end  
 until imIdx==#imageFNs  
  
end  
  
local delayTime = 2500;  
local imageStackFN = {"1.png", "2.png", "3.png"}  
slideShow(delayTime, imageStackFN)  

However, it shows only the last image (3.png). The print output works almost fine, I mean it prints the right image file names with a delay after each image. I even commented the transition.to line but still the same problem.

Any comment/solution would be appreciated.

Thanks,
Arash [import]uid: 80320 topic_id: 35474 reply_id: 335474[/import]

You have a couple of things going on. In line 6 you’re accessing finishImage, but it’s not been defined yet (at least in the code posted). Then in line 12 you create a new finishImage variable that is local only to that block of code. Whatever values you set on finishedImage before that local declaration are going to be temporarily overwritten.

Next, I think your repeat loop doesn’t actually have any real delays in it, it’s going to run as fast as it can and very possibly load all three of your images in a single frame and you will only see the last image.

I’d consider doing something a bit different. I would create a function called showImage() that shows the next image. You can use a variable to keep track of which one to show (like your repeat loop uses) and display only the one image.

Then use a timer.performWithDelay(2500, showImage, #imageStackFN)

That will cause showImage() to get called every 2.5 seconds and will run once for each image in the table.

[import]uid: 199310 topic_id: 35474 reply_id: 140986[/import]

Hi Rob,

Thanks for your solution, it works fine.

Regards,
Arash [import]uid: 80320 topic_id: 35474 reply_id: 141009[/import]

You have a couple of things going on. In line 6 you’re accessing finishImage, but it’s not been defined yet (at least in the code posted). Then in line 12 you create a new finishImage variable that is local only to that block of code. Whatever values you set on finishedImage before that local declaration are going to be temporarily overwritten.

Next, I think your repeat loop doesn’t actually have any real delays in it, it’s going to run as fast as it can and very possibly load all three of your images in a single frame and you will only see the last image.

I’d consider doing something a bit different. I would create a function called showImage() that shows the next image. You can use a variable to keep track of which one to show (like your repeat loop uses) and display only the one image.

Then use a timer.performWithDelay(2500, showImage, #imageStackFN)

That will cause showImage() to get called every 2.5 seconds and will run once for each image in the table.

[import]uid: 199310 topic_id: 35474 reply_id: 140986[/import]

Hi Rob,

Thanks for your solution, it works fine.

Regards,
Arash [import]uid: 80320 topic_id: 35474 reply_id: 141009[/import]