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?
Updating platforms in a platformer game
Re: Updating platforms in a platformer game
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.
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.
Check out my blog on gamedev
Re: Updating platforms in a platformer game
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!
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!
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Updating platforms in a platformer game
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!
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 True 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.
Re: Updating platforms in a platformer game
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:
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.
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)
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
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).
Who is online
Users browsing this forum: No registered users and 1 guest