Find my flaw, win an ‘atta boy

Here’s the deal. I wrote a bit of sample code to generate 2D terrain. (See here and here) A fellow blogger and reader pointed out a performance flaw to me and suggested I do it differently. So I did. With problems.

I’m usually posting tips and help to readers, and it’s your turn to return the favor, if you would be so kind. Find the flaw, win an ‘atta boy, pat on the back, and a thank you. Sorry, no prizes.

The original method used a series of individual vertical lines to draw a 2D side-scrolling terrain. It worked, but it could definitely kill performance if a lot of other things were going on in the game at the same time. The new method uses a single filled polygon that gets rendered all at once.

Look in the ‘draw’ method to find the code in question.

The first bit of code can be found here (ignore the part contained in #ifdef USE_OBJC):
[Download: Terrain Test - 541k]

Get the new flawed code here:
[Download: Terrain Test Polygon Render - 541k]

UPDATE:
Think I figured it out. Moving my vertices along the x-axes but connecting my polygon’s bottom corners to the same points that have been moved, thus drawing all messed up. Still wouldn’t mind some assistance figuring out the best way to do this.

UPDATE 2:
Thanks to Steffen for the suggestions and pointing out some majorly stupid (and embarrassing) flaws. Tried to hack at the problem and turn something old into something it wasn’t meant to be. Need to rework this from scratch.

UPDATE 3:
Good to know I’m no the only developer that is a bit confused. :) I’ll post my solution when it’s done.

Random Posts:

If you found this useful, shoot me a small donation or at the very least leave a comment, every bit of encouragement helps keep me motivated to update with more content on a regular basis!

Comments

*

3 Responses to “Find my flaw, win an ‘atta boy”

  1. Kris Turner says:

    This site is very enlightening and beneficial to someone whose been out of the circuit for a long time.

    - Kris

  2. Great site!!!!!!

    How can you use box 2d in conjunction with this?

    I am stumped

  3. Adam says:

    Did you ever figure out a solution? I’m just learning cocos2D at the moment, but when I’ve got the basics down I’ll definitely be looking to replicate something like this!

    Cheers.

Twitter Me