Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sprite trick

edited July 2013 in Questions Posts: 105

Hello again!

I have a question and i hope it is not as simple as the last one i asked. I am making a floor that is going to fill the whole screen, but instead of typing sprite, sprite, sprite all the time until you are done I began to wonder if there could be a shortcut somwhere that would give me more time instead of typing sprites all the time. So is there a way?



  • Posts: 689

    Alternatively could you not just use a couple of for loops to do the same thing?

        local x,y = 0,0
        for i=1,32 do
            x = 0
            for j=1,32 do
                  x = x + 32
            y = y + 32 

    The next step on from this is a "tilemap" and generating a 2D array of map values (see, the above code could easily be used to draw a tilemap by looking up the value in a simple array.

  • IgnatzIgnatz Mod
    Posts: 5,396

    It's worth using the shader approach once you get a few of these tiling situations, or if you want to use a shrunk down version of the image (images are rarely exactly the right size).

    The shader also works with irregular shaped objects.

    Using a for loop is also going to hit your performance, a shader is way faster

  • Posts: 689

    Agreed, but what about tilemap support. I haven't got much experience with shaders but could you use a single texture containing all your tiles and pass in a tile map array and just render a single quad that displayed a full map?

    Now that would be a fast approach.

  • IgnatzIgnatz Mod
    Posts: 5,396

    I'm sure you could, but you may not need a shader for that, if you set your texture mappings correctly for each vertex

  • Posts: 689

    Your probably right, I was thinking about this earlier. The only difference I can see is that if you use a mesh and set the texture coords it'll probably be easier to setup and use than trying to use a shader and I suspect the speed increase would be negligible.

  • IgnatzIgnatz Mod
    Posts: 5,396

    The real benefit of the shader is when you have fractional tiles, or an odd shaped surface, like a big triangle. Those are hard to program manually, but the shader just does them.

  • edited July 2013 Posts: 391

    I just shared my project code for 2D map generation from a 2D table (grid) using sprite sheets.

    Check it out here:

Sign In or Register to comment.