Changing background

Is there a way to set a timer in Codea to make it night and day?

Can you explain a bit more?

@CodeaNoob I made SuperCraft have night time but I wanna make some code to set a timer for it so it starts out as day and then in 7 minutes it turns night

@CodeaNoob but I would have to set to 30 seasons first

Try using tween @TeamSuperCraft

Well this do @CodeaNoob ?


rect = { x = 10, y = 10,
        width = 20, height = 20,
        fillColor = color(255) }

tween(1, rect, {x = 100, y = 100})

tween(1, rect, 
        {fillColor = color(255,0,0)})

tween(1, rect, {x = 100, y = 100},
         tween.easing.quadIn)

tween(1, rect, {x = 100, y = 100},
              tween.easing.linear)

tween(1, rect, {x = 100, y = 100},
              tween.easing.linear,
              function() 
                print("Tween Ended") 
              end)

tween(1, rect, {x = 100, y = 100},
              tween.easing.linear,
              function(param)
                  print(param)
              end, "Tween Ended")

If you want to set a timer, you can do timer=0 in setup, and then in draw() do timer=timer+DeltaTime. Or you can use tween.delay().

@Saturn031000, that timer would be good, but he wants his game on a day-night loop cycle, and a tween.path with a pingpong loop would be easier to implement

You could alsways do this…

c = color(0, 225, 255, 255)
tween(10, c, {r=0,g=0,b=0},{loop=tween.loop.pingpong})

Just change 10 to 420 if you want a loop that lasts 7 minutes for day and 7 minutes for night(60 * 7 = 420)

@TheSolderKing nah mine is a 3D project and CodeaNoob is helping me with it wen he’s done I’m going to see if I can do anything about the blocks

@TheSolderKing, thats what I gave him

Ah no I see, @CodeaNoob that is for 2d you did for 3d I believe? Sorry anyways!

Isnt 2d and 3d Color the same?

@Mr_Ninja of course, but @CodeaNoob’s forms a 3d box, whereas mine just generates a color.

@TheSolderKing, what I did draw the 3D world, then just have the background colour tweened in a pingpong loop. (Does that make sense?)

Making the background colour black doesn’t make any objects go black, because it sits behind everything.

The simplest way to make the world go dark, in 2D or 3D, is to draw a partly transparent rectangle over the whole screen after drawing everything else. This can make everything go dark.

Ah I see what they mean now, they wanted all objects to go black? Ignatz’s way is the simplest way, then.

@Ignatz, @TeamSuperCraft also wants to add torches, so your method wouldnt work

Ah, now that makes it complicated…
Shaders seem like the way to go. Not sure I can help with that though.

@TheSolderKing CodeNoob didnt send me the code yet but if he does makeit so the blocks go dark i will work on torchs