Change image depending on time of day?

Is there a way to do it?

Thank you! :slight_smile:

What image?

I mean something like a slideshow of images: this is my idea: when it is day, the background is an image with the Sun, when it’s night, the background is an image with the moon( all depending on the time)

Hi MDV,

seems like you want to tie it too the system clock then have a function call the transition of the images.

I am sure it is relatively simple to achieve using os.time /date etc, although I may corrected.

http://docs.coronalabs.com/api/library/os/time.html

We did a time tutorial about a month or so ago which covered the various time functions.

Basically though you would use the os.time() call to get the current time, feed that to the os.date() call to get the various components of the time, like the hour and then you could do:

[lua]

if hour < 6 then

     show night pic

elseif hour < 8 then

     show sunrise pic

elseif hour < 18 then

     show daytime pic

elseif hour < 20 then

     show sunset pic

else

     show night pic

end

[/lua]

or some similar logic.

EDIT: That’s not real code, but just the logic.

What image?

I mean something like a slideshow of images: this is my idea: when it is day, the background is an image with the Sun, when it’s night, the background is an image with the moon( all depending on the time)

Hi MDV,

seems like you want to tie it too the system clock then have a function call the transition of the images.

I am sure it is relatively simple to achieve using os.time /date etc, although I may corrected.

http://docs.coronalabs.com/api/library/os/time.html

We did a time tutorial about a month or so ago which covered the various time functions.

Basically though you would use the os.time() call to get the current time, feed that to the os.date() call to get the various components of the time, like the hour and then you could do:

[lua]

if hour < 6 then

     show night pic

elseif hour < 8 then

     show sunrise pic

elseif hour < 18 then

     show daytime pic

elseif hour < 20 then

     show sunset pic

else

     show night pic

end

[/lua]

or some similar logic.

EDIT: That’s not real code, but just the logic.