- Home /
Grid of gameobjects vs SetPixel
For basic 2D tiled games I've always been setting up a 2D grid of quads or recently with 4.3 sprites. I've never had a problem with this system for small sokoban or puzzle games or just simple roguelikes without any major ai or mechanics. Anyway, I was hoping to move onto my next major project using a 2D grid of 10x10pixel sprites with a fixed resolution of 320x180.
So basically I would have a 32x18 grid gameobjects with a sprite renderer attached. My sprites are simple black and white sprites (old school ascii but with a couple of original's thrown in), I have 2 layers to the grid so in total 1152 gameobjects with sprite renderers in the scene. The background grid basically with 10x10 sprites of solid colour and the foreground grid drawing the ascii sprites. On top of that I will have a couple of actors that will have their own gameobject in the scene, however all gameobjects will be instantiated at load time.
TL;DR, I've been using a layers of sprite gameobjects in a grid to do my 2d games.
I was wondering, as the game gets more complex am I better of using SetPixel for this project where I will only be using Apply once each Update() call?
Also is there a convenient way for me to make the black parts of my sprite one colour and the white parts another?
Sorry if this question isn't very well written, its much past my bed time...
Also is there a convenient way for me to make the black parts of my sprite one colour and the white parts another?
This is easy task with a simple shader. $$anonymous$$ake shader that takes two colors and black-white image and in render pass put other color onto black and other color onto white pixels.
Answer by robertbu · May 10, 2014 at 04:27 PM
SetPixel is likely not the answer.
More efficient is to use a texture atlas and change the uv coordinates of your quad. A bit complicated but not hard to hand-code, but third-party UI systems like NGUI and EZGUI will automate this process.
Even better is to build many quads out of a single mesh and use uv coordinates to map the quads to textures in a texture atlas.
Search for 'Unity3d Atlas'.
@robertbu Wouldn't it be better still to just use Sprite's, using unity's sprite atlasing?
Unity hides a lot of sprite functionality, so I have no idea what they do under the hood. And I've never run any performance tests on Unity's sprites. $$anonymous$$y guess is that it would be as efficient as the first suggestion but not as efficient as the second suggestion. The second suggestion is technically more difficult to implement, but uses only a single drawcall for up to 16,000 quads.
Your answer
Follow this Question
Related Questions
Get position from Isometric TileMap 1 Answer
Block puzzle (1010) help 0 Answers
2D Grid Question 0 Answers
How to make 2d distortion? 2 Answers
2D texture loaded from file different from same texture in editor 2 Answers