Jump to content
  • Advertisement
Sign in to follow this  
nick5454

OpenGL Looking for source code for a tiled 2d scroller

This topic is 1500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

I'm looking for source code for a simple 2d scroller like mario brothers. Does anyone know of link where I can purchase the code? I don't need a complete game, just the basic engine to side scroll. I checked code canyon, but all they have is UIKit scrollers.

 

I want to use it on iOS iPhone and would rather purchase source code to move fast. I understand opengl for the most part, but am not sure how to draw tile maps in opengl. Just looking for starter code and I am willing to buy the source.

 

Thanks,

Nick

Share this post


Link to post
Share on other sites
Advertisement

Hey Nick

 

Displaying and scrolling a map is relatively easy, and i'm sure you can find someone who may sell you this code.. but i don't think its worth purchasing. If you wish to build a platform game, but are unable to build the map, we may not be at a stage to progress said game, so it may not be any faster to develop - you may just be out of pocket.

 

For a simple example of a tile map, use and array, you use the indices to calculate the postion of each tile, and use the value for your tile type, eg 1: Wall, 0: Grass, 2: Water 

int tileSize = 128;
int map[5][5] = {
1,1,1,1,1,
1,0,0,0,1,
1,0,2,0,1,
1,0,0,0,1,
1,1,1,1,1
}
 
...
 
for( int y = 0; y < 5; y++ ) {
     for( int x = 0; x < 5; x++ ) {
         DrawTile( x * tileSize, y * tileSize, map[y][x] )
    }
}
 
...
 
DrawTile( int postionX, int positionY, int tileID ) {
...
}
Edited by McGrane

Share this post


Link to post
Share on other sites

I had the problem of displaying the tiles correctly. I could display one, but my buffer arrays were incorrect. I'll try and find the source code and post it.

Share this post


Link to post
Share on other sites

Here's what I have. The sprite sheet is 1024x1024 with 64x64 sprite squares.

- (void)setSprite:(NSString *)fileName effect:(GLKBaseEffect *)newEffect {

    // 1
    self.effect = newEffect;
        
    // 2
    NSDictionary * options = [NSDictionary dictionaryWithObjectsAndKeys:
                                  [NSNumber numberWithBool:YES],
                                  GLKTextureLoaderOriginBottomLeft,
                                  nil];
        
    // 3
    NSError * error;
    NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:nil];
    
    // 4
    self.textureInfo = [GLKTextureLoader textureWithContentsOfFile:path options:options error:&error];
    if (self.textureInfo == nil) {
        NSLog(@"Error loading file: %@", [error localizedDescription]);
            return ;
    }
    
    NSLog(@"Value of %f", 64.0f/1024.0f);

    TexturedQuad newQuad;
    newQuad.bl.geometryVertex = CGPointMake(0, 0);
    newQuad.br.geometryVertex = CGPointMake(64.0f/self.textureInfo.width, 0);
    newQuad.tl.geometryVertex = CGPointMake(0, self.textureInfo.height);
    newQuad.tr.geometryVertex = CGPointMake(64.0f/self.textureInfo.width, self.textureInfo.height);

    newQuad.bl.textureVertex = CGPointMake(0, 1);
    newQuad.br.textureVertex = CGPointMake(64.0f/1024.0f, 1);
    newQuad.tl.textureVertex = CGPointMake(0, 0);
    newQuad.tr.textureVertex = CGPointMake(64.0f/1024.0f, 0);
    
    self.quad = newQuad;
    

}

My problem is just displaying 2 frames ( square(0,0) - tile 1 and tile 2(0,0) )

Share this post


Link to post
Share on other sites

You could try Cocos2D (or Cocos2D-x if you're more into C++). It has all sprite routines, transitions and boilerplate code, and has support for TMX tilemaps for which handy editors are available. It is well tested and will probably save you about two years of your time. Best of all, it is free.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!