Make Screen Scroll faster on Increment

Hello again!

I need help desperately with this one. When my screen is scrolling on the game it stays at a constant speed. I would like it to slowly increase in speed as the game goes on to make it more and more difficult for the player but I cannot get my head round it. I’ve come up with this so far but nothing changes and no error is given it just stays at a constant speed:

nMilliseconds = 500 incrementfortime = 750 val = 11 increment = 1 nMilliseconds = nMilliseconds + incrementfortime while val \< 15 do &nbsp;&nbsp;&nbsp;&nbsp;system.getTimer( ) &nbsp;&nbsp;&nbsp;&nbsp;timer.performWithDelay(nMilliseconds) &nbsp;&nbsp;&nbsp;&nbsp;val = val + increment end function scrollCity(self,event) if self.x \< -2400 then self.x = 2560 else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.x = self.x - val &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;end&nbsp; &nbsp;

All help is welcome and thank you very much for your time,

James

One way might be to use the Corona transition library!

Most of the examples for transitions are around moving an object, but in reality, you can transition a simple value.  The only requirement is your target for the transition be a table.  Instead of using “val”, you could use t.val.

Here is an example that slowly increases a value named speed over 30 seconds. 

The value speed is held as part of a table (t) - that is the trick to leveraging the transition library.

All the different types of easings work, too: https://docs.coronalabs.com/api/library/easing/index.html

Of note, using transition will make speeding up the city smooth, as well as slowing it down.  Let’s say you have different city levels. Your game could get faster and faster until it gets to the hardest level. then, when the user gets to the end, you could do a speed transition to val=0 over a few seconds.

The result would be the city scrolling slowing down smoothly and gradually. Additionally, you could call the onComplete to then pop-up their score.

Good luck, hope this helps!

local t= {} t.speed = 5 local iSecondsToTransition = 30 function showt() -- (All math.floor does is drop the fractional speed percentages. -- Comment to next line to see the raw values. t.speed = math.floor( t.speed ) print ( t.speed ) if t.speed\>59 then Runtime:removeEventListener( "enterFrame", showt ) end end Runtime:addEventListener( "enterFrame", showt ) transition.to( t, { time=iSecondsToTransition \*1000 , speed=60 } )

One way might be to use the Corona transition library!

Most of the examples for transitions are around moving an object, but in reality, you can transition a simple value.  The only requirement is your target for the transition be a table.  Instead of using “val”, you could use t.val.

Here is an example that slowly increases a value named speed over 30 seconds. 

The value speed is held as part of a table (t) - that is the trick to leveraging the transition library.

All the different types of easings work, too: https://docs.coronalabs.com/api/library/easing/index.html

Of note, using transition will make speeding up the city smooth, as well as slowing it down.  Let’s say you have different city levels. Your game could get faster and faster until it gets to the hardest level. then, when the user gets to the end, you could do a speed transition to val=0 over a few seconds.

The result would be the city scrolling slowing down smoothly and gradually. Additionally, you could call the onComplete to then pop-up their score.

Good luck, hope this helps!

local t= {} t.speed = 5 local iSecondsToTransition = 30 function showt() -- (All math.floor does is drop the fractional speed percentages. -- Comment to next line to see the raw values. t.speed = math.floor( t.speed ) print ( t.speed ) if t.speed\>59 then Runtime:removeEventListener( "enterFrame", showt ) end end Runtime:addEventListener( "enterFrame", showt ) transition.to( t, { time=iSecondsToTransition \*1000 , speed=60 } )