day/night cycle

Hi, dumb question time I’m pretty new to corona I was wondering if there is a guide to do a night/day cycle. Basicly I just want the background to change to night time and have NPC people react to it being night ie they sleep.

Just wanted to be pointed in the right direction or given a place to look.

Many thanks [import]uid: 171762 topic_id: 30018 reply_id: 330018[/import]

You could create two functions, day and night, and then check the time every now and then to see if you need to change. Something like this:
[lua]local person=display.newRect(0, 0, 50, 50)
person:setFillColor(0, 0, 255)
local bed=display.newRect(0, 0, 60, 120)

local function day()
if bedTrans then
transition.cancel(bedTrans)
end
movementTrans=transition.to(person, {x=math.random(1024), y=math.random(1024), time=5000})
–You could also change the background
end

local function night()
if movementTrans then
transition.cancel(movementTrans)
end
bedTrans=transition.to(person, {x=bed.x, y=bed.y, time=2000})
–same here
end

local function dayOrNight()
local t=os.date()
local hour=t.hour
if hour>6 and hour<9 then
day()
else
night()
end
end
dayOrNight()
timer.performWithDelay(60000, dayOrNight, 0)[/lua]
That code is completely untested, but it might be a pointer in the right direction. Of course, the day and night functions would be much more advanced, but that’s a starting point.

quinc [import]uid: 147322 topic_id: 30018 reply_id: 120243[/import]

Thanks for the help

thats a pretty good start and helps me a lot

thank you again. [import]uid: 171762 topic_id: 30018 reply_id: 120248[/import]

Ill be honest im pretty much just starting out with this I have my head stuck in a book and im learning bits as I go.

I am just a game designer but struggling to get anywhere so next best thing was to make my own games but sadly dont have any programming skill or money to pay a programmer.

I have had two programmers in the past but after a few weeks they dropped off the radar for whatever reason so im trying the hard way and learning it myself.

hopefully maybe in 4 years time ill have the game out lol

anyway thanks for the advice and help. [import]uid: 171762 topic_id: 30018 reply_id: 120251[/import]

You could create two functions, day and night, and then check the time every now and then to see if you need to change. Something like this:
[lua]local person=display.newRect(0, 0, 50, 50)
person:setFillColor(0, 0, 255)
local bed=display.newRect(0, 0, 60, 120)

local function day()
if bedTrans then
transition.cancel(bedTrans)
end
movementTrans=transition.to(person, {x=math.random(1024), y=math.random(1024), time=5000})
–You could also change the background
end

local function night()
if movementTrans then
transition.cancel(movementTrans)
end
bedTrans=transition.to(person, {x=bed.x, y=bed.y, time=2000})
–same here
end

local function dayOrNight()
local t=os.date()
local hour=t.hour
if hour>6 and hour<9 then
day()
else
night()
end
end
dayOrNight()
timer.performWithDelay(60000, dayOrNight, 0)[/lua]
That code is completely untested, but it might be a pointer in the right direction. Of course, the day and night functions would be much more advanced, but that’s a starting point.

quinc [import]uid: 147322 topic_id: 30018 reply_id: 120243[/import]

Thanks for the help

thats a pretty good start and helps me a lot

thank you again. [import]uid: 171762 topic_id: 30018 reply_id: 120248[/import]

Ill be honest im pretty much just starting out with this I have my head stuck in a book and im learning bits as I go.

I am just a game designer but struggling to get anywhere so next best thing was to make my own games but sadly dont have any programming skill or money to pay a programmer.

I have had two programmers in the past but after a few weeks they dropped off the radar for whatever reason so im trying the hard way and learning it myself.

hopefully maybe in 4 years time ill have the game out lol

anyway thanks for the advice and help. [import]uid: 171762 topic_id: 30018 reply_id: 120251[/import]