Search Unity

Making a box reuse sprites linearly (e.g. platform)

Discussion in '2D' started by bluefoxicy, Jan 6, 2015.

  1. bluefoxicy

    bluefoxicy

    Joined:
    Jan 2, 2015
    Posts:
    15
    I have a 32x32 sprite sheet with four tiles: left end, segment 1, segment 2, right end.

    Can Unity make a 10 unit rectangle whereby it uses {left end, segment 1, segment 2, segment 1, segment 2, ... right end}? Can this be scripted or otherwise done automatically?

    Took a glance through the forums; nothing jumped out, and I don't have the domain-specific vocabulary to know what to search for. Sorry if this has been asked.


    EDIT: Hmm, it would be nifty if I could get Unity 4.6's Grid layout to let me make a whole layer a grid of elements, and then drop my 32x32 sprites into them.
     
    Last edited: Jan 6, 2015
  2. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    It sounds like you are referring to auto tiling. You cannot have multiple sprite renderer components attached to a single game object, however you could attach multiple sprite renderer individual game objects and bind them together via a parent game object. If you were to do that however the number of segments would generally have to be the same, and requires alot of game objects to boot. There is a project in the Unity store called AutoTile if you are willing to spend a few $$$, I don't think it's all that expensive. But if you wanted to go about it yourself I would start by researching the auto tiling process and how it works. I have used it before with great success in top down games and such, but never have used it for platforms and what have you. I highly recommend the AutoTile store package in your case, good luck.
     
  3. bluefoxicy

    bluefoxicy

    Joined:
    Jan 2, 2015
    Posts:
    15
    Nod. I could use an add-on, or build my own tiles.

    I've also considered using the Grid layout to make a grid of 32x32 pixel tiles on the platform and background layers; but it doesn't look like I can just drop straight sprites on a grid. Plus, then I'd need to make any active platforms some number of tiles wide, and put a layout under them and add in their sprites, and whatnot.

    I'm trying to do the visual style of 2D games like Megaman or Legend of Zelda. I don't know if you could realistically pull off non-tile-aligned pixel art visual style without looking just goofy. There's a difference between this style of game:



    And something with a higher level of detail:



    I'm not sure I could be freeform in low-detail.
     
  4. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    I do tiled games using pixel art all the time, it is very doable but takes quite a bit of research and practice. The grid layout is the best way to do it, but you don't display all those sprites at once. What you will do is have an array of tile data that forms the grid, the tile data knows what sprite it will need and such. Then you fill only the camera area the player can see with tile game objects. You can even have these in layers so some are behind others or on top of them to simulate things like a plate of food on a table for example. Anyways, you update the tiles filling the camera area as the player moves feeding them with the sprite data appropriate their location. You might also consider the need to enable/disable tiles that will be displaying nothing for that moment using a sort of pooling system.

    This is also where an autotiling algorithm will shine. Especially if your map tiles are mostly static minus game objects like enemies and players (which are obviously not tiles). You can develop a map editor and place things where they need to be, autotile them once and forget about having to do it again unless you change tiles. If some of the tiles are dynamic then autotiling may have to be a part of your regular game algorithm in some way, but I will leave you to figure all that out. Good luck.

    P.S. Orthographic size and pixel snap will become incredibly useful in a grid based game.