Buffing Up Our Platforms

Last time we built a quick class to get our scene moving, but that’s not particularly helpful until we have something to move. In this post, we’ll add a set of platforms to our scene.

This first step is to create a new class that sub-classes our ScrollingNode that we built in the last post.

#import “ScrollingNode.h”
@interface PlatformNode : ScrollingNode

This will ensure that whatever we add to this whatever we add to our PlatformNode will be able to scroll at whatever speed we decide, which was the point of our work in the last post.

Now that we have a class to get things started (or scrolled), we will build a way to keep track of a set of platforms.

One of the advantages of using a procedural level generator, is that it can lower our overhead when it comes to keeping a number of  large map or level in system memory. So, as we build our platform side-scroller we have to keep in mind that we want to limit the total number of platforms that our program will need to keep track of at any given time.

To do this, we’ll build a platform buffer to limit the number of platforms we track. Change our PlatformNode.h file as shown below:

@interface PlatformNode : SKScrollingNode
NSMutableArray *platformBlockBuffer;
@property (nonatomic) NSUInteger platformBufferSize;


What we’ve done is to add:

  1. A Mutable Array that can store any number of objects. We’ll use this to store our Platform Nodes.
  2. An Integer to track how many Platform Nodes we’ll keep track of.

The next step is to make sure these two variables get set up correctly; in our PlatformNode.m file, change our init method as shown below:

- (id) init
if (( self = [super init] ))
platformBlockBuffer = [[NSMutableArray alloc] init];
self.platformBufferSize = 10;// Generate the first set of platform tiles on the Ground
for (int i = 0; i < self.platformBufferSize; i++)
// Generate a New Platform
return self;


All this code does is to:

  1. Instantiate our Platform Buffer array.
  2. Set our Platform Buffer size to a default value (I’ve just used 10 here because it’s easy.
  3. Added a loop that will fill up our Platform Buffer.

Now all we’ll need to do is to come up with a way to Generate our Platforms, which we’ll do in our next post.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>