Unity Community


Results 1 to 13 of 13

  1. Location
    Australia
    Posts
    353

    2D side-scroller with Unity

    Hi,

    I'm looking for tutorials on how to setup/make level design in Unity for 2D side scroller game using sprites.

    If anyone has some links or maybe some general ideas please share. I've never made side scroller game before so have hard time visualizing how I should set it all up in Unity editor.

    Thanks in advance.


  2. Posts
    1,082
    I would make my levels in Tiled (mapeditor.org).

    The format is a bit bloated, so I have a script that converts it to a csv-like format with only the stuff I need.

    Then you can read that and make meshes from it.
    Last edited by Mudloop; 12-01-2010 at 04:11 AM.
    UniTile - 2d Tile-based Map Editor for Unity - now also available in the Asset Store.

    My games :
    - ReRave (for iOS and Arcade)
    - Robin Hood - Archer of the Woods (published by Chillingo/Clickgamer)
    - Pig Shot (published by Nexx Studio)
    - Captain Ludwig
    - Pinkvasion
    - Deep
    - iPigeon


  3. Location
    Australia
    Posts
    353
    Quote Originally Posted by Smag
    I would make my levels in Tild (mapeditor.org).

    The format is a bit bloated, so I have a script that converts it to a csv-like format with only the stuff I need.

    Then you can read that and make meshes from it.
    Thanks mate!

    It might sound stupid, but do you create those meshes in Unity Editor script and can view in design mode or create them in the runtime?


  4. Posts
    1,082
    I guess both could work, but I do it at runtime. For a rather big level it takes 3 to 5 seconds, which is okay.

    If I did it in the editor I would have to run the script every time I changed something in the level, and I'm too lazy for that

    My conversion to the csv-type format is done with php btw. It checks all the maps that have changed (modification date > the corresponding csv's modification date) and only converts the changed maps.
    UniTile - 2d Tile-based Map Editor for Unity - now also available in the Asset Store.

    My games :
    - ReRave (for iOS and Arcade)
    - Robin Hood - Archer of the Woods (published by Chillingo/Clickgamer)
    - Pig Shot (published by Nexx Studio)
    - Captain Ludwig
    - Pinkvasion
    - Deep
    - iPigeon


  5. Posts
    373
    @Smag

    Don't suppose you'd be willing to share your script? would you?

    I might have a look at the file format and see if I can't whip something together...Could be very useful I would imagine.
    Mike Hovland
    Blue Rocket Labs
    Click above and "Like" our Facebook page
    to be entered to win a *FREE* Blue Rocket Labs T-Shirt!


  6. Posts
    1,082
    Sure, if I can remember once I'm behind my macbook.
    UniTile - 2d Tile-based Map Editor for Unity - now also available in the Asset Store.

    My games :
    - ReRave (for iOS and Arcade)
    - Robin Hood - Archer of the Woods (published by Chillingo/Clickgamer)
    - Pig Shot (published by Nexx Studio)
    - Captain Ludwig
    - Pinkvasion
    - Deep
    - iPigeon


  7. Posts
    1,082
    Here it is.
    It requires this : http://www.ibm.com/developerworks/xm...x-xml2jsonphp/

    It converts tsx files (tilesets) to json files, and tmx files (the tilesets) to something csv-like. I could probably have used a binary format to save more space, but meh

    Code:  
    1. <?php
    2. require_once("xml2json.php");
    3. ini_set("memory_limit","512M");
    4.  
    5.  
    6. $from = 'source/directory/';
    7. $to = 'destination/directory/';
    8. $backups = 'backups_directory/';
    9.  
    10. if ($dh = opendir($from)) {
    11.     while (($file = readdir($dh)) !== false) {
    12.         $from_path = $from . $file;
    13.         $to_path = $to . $file . '.txt';
    14.         set_time_limit(300);
    15.         if(is_file($from_path) && $file[0]!='.') {
    16.             $from_date = filemtime($from_path);
    17.             $to_date = 0;
    18.             if(is_file($to_path)) {
    19.                 $to_date = filemtime($to_path);
    20.             }
    21.             if($from_date > $to_date) {
    22.                 if($to_date > 0) rename($to_path, $backups . $file .'.txt');
    23.                 $explode = explode('.', $file);
    24.                 $ext = $explode[count($explode) - 1];
    25.                 $content = file_get_contents($from_path);
    26.                 $jsonContents = xml2json::transformXmlStringToJson($content);
    27.                 if($ext == 'tmx') {
    28.                    
    29.                     $o=json_decode($jsonContents);
    30.                     $layers=$o->map->layer;
    31.                     $a="@attributes";
    32.                     $output='';
    33.                    
    34.                     $output.=$o->map->$a->width.",";
    35.                     $output.=$o->map->$a->height.",";
    36.                     $output.=$o->map->$a->tilewidth.",";
    37.                     $output.=$o->map->$a->tileheight;
    38.                     for($i=0;$i<count($layers);$i++) {
    39.                         $output.="\n";
    40.                         if(is_array($layers)) {
    41.                             $layer=$layers[$i]->data->tile;
    42.                         } else {
    43.                             $layer=$layers->data->tile;
    44.                         }
    45.                        
    46.                         for($j=0;$j<count($layer);$j++) {
    47.                            
    48.                             if($j>0) $output.=",";
    49.                             $output.=$layer[$j]->$a->gid;
    50.                         }
    51.                        
    52.                     }
    53.                    
    54.                     $handle = fopen($to_path, 'w');
    55.                     fwrite($handle, $output);
    56.                     fclose($handle);
    57.                     echo 'Converted map : '.$file.'
    58. ';
    59.                    
    60.                    
    61.                 } elseif ($ext == 'tsx') {
    62.                     $handle = fopen($to_path, 'w');
    63.                     fwrite($handle, $jsonContents);
    64.                     fclose($handle);
    65.                     echo 'Converted tileset : '.$file.'
    66. ';
    67.                 }
    68.             } else {
    69.                 echo 'Skipped file : '.$file.'
    70. ';
    71.             }
    72.         }
    73.        
    74.     }
    75.     closedir($dh);
    76. }
    77.  
    78. ?>
    UniTile - 2d Tile-based Map Editor for Unity - now also available in the Asset Store.

    My games :
    - ReRave (for iOS and Arcade)
    - Robin Hood - Archer of the Woods (published by Chillingo/Clickgamer)
    - Pig Shot (published by Nexx Studio)
    - Captain Ludwig
    - Pinkvasion
    - Deep
    - iPigeon


  8. Location
    California
    Posts
    12

    Can Anyone help me implement this?

    Hey has anyone successfully gotten the PHP script to work? Also how do you integrate the json data into unity?
    Plz help!


  9. Posts
    1,082
    Actually, it doesn't convert to JSON anymore. That was my first plan, but then I changed the format to csv, but I think it still uses the json as an intermediary step because I used JSON first.

    What exactly are you having trouble with?
    UniTile - 2d Tile-based Map Editor for Unity - now also available in the Asset Store.

    My games :
    - ReRave (for iOS and Arcade)
    - Robin Hood - Archer of the Woods (published by Chillingo/Clickgamer)
    - Pig Shot (published by Nexx Studio)
    - Captain Ludwig
    - Pinkvasion
    - Deep
    - iPigeon


  10. Location
    California
    Posts
    12
    Quote Originally Posted by Smag View Post
    Actually, it doesn't convert to JSON anymore. That was my first plan, but then I changed the format to csv, but I think it still uses the json as an intermediary step because I used JSON first.

    What exactly are you having trouble with?
    I am having trouble building 2d levels with Mapeditor and getting them into unity. One way I was trying this was exporting to PNG format and drawing in all the collider's.

    Is there any way you can walk me through importing the data generated by your PHP script into unity?


  11. Posts
    1,082
    Well, I can't give you my code, because it has dependencies on other classes of mine, and I don't want to give away my entire codebase
    PNG's are a bad idea since it will increase your filesize a lot if you have many levels.

    What I do is I loop through the csv format, and construct meshes of 10x10 tiles. It's not that difficult - it's basically the same as creating sprites, but you just add a little more to each one. Figuring out the right coordinates and uv's based on the numbers in the csv can be a bit tricky though.

    Good luck!
    UniTile - 2d Tile-based Map Editor for Unity - now also available in the Asset Store.

    My games :
    - ReRave (for iOS and Arcade)
    - Robin Hood - Archer of the Woods (published by Chillingo/Clickgamer)
    - Pig Shot (published by Nexx Studio)
    - Captain Ludwig
    - Pinkvasion
    - Deep
    - iPigeon


  12. Location
    Germany
    Posts
    19
    I can recommend to use sprite manager 2 (SM2) and a mixture out of
    not rendered 3D meshes (for the collision), plain textures and sprites.
    (Use an 'orthographic' camera to get this 2D arcade feeling )

    "PEP the dragon" is created that way and as it uses mostly 2D artwork
    it runs fine, even on older apple devices.

    You can see a flash demo on http://www.pepworks.com/ or download
    the LITE version in the app store to see how it look and feels.

    best regards,

    pep


  13. Location
    london
    Posts
    36
    i defo agree SM2 will cut out a lot of optimization work and donkey work. i am currently trying to create a side scroller for iphone and i realised early on that the draw calls would kill the whole game. i have been using SM2 for just a day now and have got great results already.




    death by pixel
    www.deathbypixel.co.uk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •