Speed Increase suggestions for Endless runner

Hello again,
I am almost close to finishing my first ever game, thanks to all your help till now.
While my game runs fine with a fixed speed (for parallax effect), I am unable to find a good balance to increase speed of my game as time progresses.
Here is my current setup, with delta time considerations. Currently, I increase speed every 5 secs, but that seems non-linear/jerky, my game feels there is sudden increase of speed instead of a smooth gradual one.

local speed = 100

local function increaseSpeed()
    speed = speed*1.1
end

local function update() 
    -- delta time calc
	local curT = system.getTimer()
	local dT = (curT - lastT)/1000
	lastT = curT
	local dX = math.round(dT * speed)
	
    for i = 1, #backgrounds do
	   local b = backgrounds[i]
	   b:translate(-(dX * .5), 0)
	end
end

timer.performWithDelay(5000, increaseSpeed, 0)
Runtime:addEventListener("enterFrame", update)

How can I make my speed a function of timeElapsed, while taking into account the deltaTime considerations as well to have a smooth/gradual game speed increase ?

Instead of increaseSpeed() immediately setting the new speed value, you could have it call a transition which increases the value over a second or so.
Here’s a simplified example, just so you can see how the data changes:

local data = {speed = 1}
 
local function increaseSpeed()
	transition.to(data, {time = 1000, speed = data.speed * 1.1})
end
 
local function update() 
    print(data.speed)
end

timer.performWithDelay(5000, increaseSpeed, 0)
Runtime:addEventListener("enterFrame", update)

You’d need to make sure that you cancel the transition when needed (when you remove the enterFrame listener I guess).

1 Like

Thank you @alanFlickGames
So I get the idea of linear increase on my speed
And this is what it looks like for me

 local data = {speed = 50, heroGravity = 1}

    function increaseSpeed()
    	transitionHandler = transition.to(data, {
    		time = 5000,
    		speed = data.speed + 5, 
    		onComplete = function()
    			transition.cancel(transitionHandler)
    			increaseSpeed()
    		end
    	})
    end 

      local function update() 
    	-- take into account frame calculations
    	local curT = system.getTimer()
    	local dT = (curT - lastT)/1000
    	lastT = curT
    	local dX = math.round(dT * data.speed)
    	
    	for i = 1, #backgrounds do
    		local b = backgrounds[i]
    		b:translate(-(dX*.5), 0)
    	end
    end

     function scene:create( event )
        increaseSpeed()
        Runtime:addEventListener("enterFrame", update)
    end

While the speed increases fine, but now I am back to flickers on background move, there is a frame drop every now and then :cry:
What else can I do to get rid of these flickers.

My update() just recycles through 3 background, 3 midbackground, 3 platforms, which I recycle based on there screen location using math.random() limits