Updating platforms in a platformer game

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Updating platforms in a platformer game

Post 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?
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Updating platforms in a platformer game

Post 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.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Updating platforms in a platformer game

Post 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!
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Updating platforms in a platformer game

Post 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! :)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Updating platforms in a platformer game

Post 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.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Updating platforms in a platformer game

Post 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).
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests