Jump to content

  • Log In with Google      Sign In   
  • Create Account

Looking for source code for a tiled 2d scroller


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 nick5454   Members   -  Reputation: 127

Like
0Likes
Like

Posted 10 July 2014 - 08:13 AM

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



Sponsor:

#2 McGrane   Members   -  Reputation: 1087

Like
0Likes
Like

Posted 10 July 2014 - 08:30 AM

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, 10 July 2014 - 08:34 AM.


#3 nick5454   Members   -  Reputation: 127

Like
0Likes
Like

Posted 10 July 2014 - 08:34 AM

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.



#4 nick5454   Members   -  Reputation: 127

Like
0Likes
Like

Posted 10 July 2014 - 01:13 PM

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) )



#5 Prototype   Members   -  Reputation: 1353

Like
0Likes
Like

Posted 10 July 2014 - 01:38 PM

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.



#6 nick5454   Members   -  Reputation: 127

Like
0Likes
Like

Posted 10 July 2014 - 03:46 PM

Actually I found this which uses a sprite sheet, so I can just modify the code and run with it. http://codecanyon.net/item/openglesopenal-sliding-puzzle-game-starter-kit/577119




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS