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]