Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Working with time based stuff - Gideros Forum

Working with time based stuff

Hey everyone :)

In my descent games the players score is basically based on the amount of time they have been playing. In my EnterFrame code I just added the event.deltaTime to a currentDepth variable and that worked. Some time after release, I got an email saying that if a user paused the game and then resumed some time later, their score would increase a lot while they were not even playing.

The problem here is that when the app is in a suspended state, event.deltaTime still increases so when the app resumes normal operation the event.deltaTime has accumulated and depending on the suspend duration, may be very large.

To resolve the issue I added the following code into my game scene..
function Game:onApplicationSuspend()
  --print('entered a suspended state')
  self.suspendStart = os.timer() -- save time at start of suspend
end
 
function Game:onApplicationResume()
  --print('resumed from a suspended state')
  self.suspendDuration = os.timer() - self.suspendStart -- calculate suspend duration
  self.resumed = true
end
 
-- update every frame
function Game:update(e)
  local dt = e.deltaTime
 
  -- manage issue when resuming from suspended state causes dt value to be accumulated (very large)
  if self.resumed then
    dt -= self.suspendDuration -- correct dt
    self.resumed = false
  end
 
  local currentDepth = self.currentDepth + dt -- this is now correct after resuming from suspended state
end
So I was curious how other people manage this issue, or if they have even faced this issue at all?

If there is no other solution than polling every frame (ughhh) then would it be possible to..
a) Introduction a new application:resetDT() function to Gideros so on resuming from a suspended state you could call this to reset deltaTime back to 0.
b) Have a project setting in Gideros Studio to choose if deltaTime will be reset automatically on resuming from a suspended state.

What do you think?

Likes: SinisterSoft

+1 -1 (+1 / -0 ) Share on Facebook

Comments

Sign In or Register to comment.