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?
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 http://www.mapeditor.org/), the above code could easily be used to draw a tilemap by looking up the value in a simple array.
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
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.
I’m sure you could, but you may not need a shader for that, if you set your texture mappings correctly for each vertex
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.
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.
I just shared my project code for 2D map generation from a 2D table (grid) using sprite sheets.
Check it out here: http://twolivesleft.com/Codea/Talk/discussion/3058/