Page 1 of 1

Updating platforms in a platformer game

Posted: Mon Mar 14, 2016 8:23 am
by molul
I have a small doubt about my platformer project. I've always thought that platforms position should be updated only when they are close to the current viewport. However, I've always had problems when I put some platforms in the stage to work as a group. For instance:

-Four platforms moving in a circle.
-Some platforms in a row, made so the odd platforms end position are next to even platforms start positions.

So I was thinking on just always updating all platforms in the stage and only drawing them when they're close to current viewport.

My doubt is: am I doing it right? Would that be bad for performance? And if so, is there any trick you could tell me to do it better, please?

Re: Updating platforms in a platformer game

Posted: Mon Mar 14, 2016 8:39 am
by micha
I think it is fine to update all of the platforms in the level. Unless you have multiple thousands of platforms, I think you will not get performance problems.
And before you put effort into some performance-optimization-tricks, I suggest you implement the simplest solution (=update all platforms). Only if you notice performance problems, you should start optimizing.

Re: Updating platforms in a platformer game

Posted: Mon Mar 14, 2016 8:42 am
by molul
Thank you. Yes, trying before thinking of optimizing makes sense, but still, I wanted to make sure that I wasn't doing something I should fix eventually.

As I plan on having not very long stages (more Mario-style than Sonic-style), yes, I guess it won't be a problem.

Well, thanks again!

Re: Updating platforms in a platformer game

Posted: Mon Mar 14, 2016 8:57 am
by zorg
Imagine games that need to keep their whole levels' states persistent for various reasons, like terraria (both playing solo or with others).
Usually, most games won't be impacted too negatively if you update state but don't render the unseen parts.
Take (open)TTD as another example, where you can open separate viewports to other areas of the map you're not currently seeing; it renders those as well, without too much impact! :)

Re: Updating platforms in a platformer game

Posted: Mon Mar 14, 2016 10:02 am
by ivan
One simple solution I found (and used in 8-Bit Commando) is:
interpolate the platform position based on the total time elapsed since the level was loaded.
Using this approach, it doesn't matter at what point the platform appears on screen:

Code: Select all

local r = time/period
r = r%1 -- wrap platform
local x = initialX + r*(finalX - initialX)
local y = initialY + r*(finalY - initialY)
platform:setPosition(x, y)
r = r%1 is basically a sawtooth wave.
For platforms, it's common to use other waveforms like triangle or sine:
http://2dengine.com/doc/gs_wave.html
So yea, waveforms are the way to go IMO.

Re: Updating platforms in a platformer game

Posted: Mon Mar 14, 2016 10:35 am
by molul
Thanks! I was somehow using that, although I didn't thought of the movement as a sine wave, but as a circle perimeter, and then the platform moves on x or y or both. The effect is the same (the platform moves slower when reaching the edges).