I am trying to make game like in led screen. The gui nodes is the best way to emulate one led
Could you use a tile map instead?
I am not using tilemap before. Can I change tile color in runtime? Looks like I can’t. GUI is the best, because tinting, not break a batch.
I haven’t used tilemaps either and as you say it looks like you can’t change the color, at least not on individual parts. But you could maybe solve it with a tilemap anyway, if you are only having a set amount of colors you could have them on the tilemap and change the ones you want to “light up” with tilemap.set_tile to one of the colored tiles.
Another approach is to simply divide your gui scene into more than one gui scene.
No tilemap, not my choice. Yes dividing will help me. But I am interested why 1024 is limit? All other limits, go, sprites and etc. Can be changed, but this not.
In a tilemap, you can switch tile with tilemap.set_tile(). So if you have a bunch of differently colored tiles, that might work.
The limit of 1024 gui nodes is there for performance optimisation reasons. Internally, a mixed key with the node index and other attributes are combined for efficient sorting of nodes.
This has nothing to do with the editor, the value can’t just simply be exposed as a variable.
The gui can of course be used to build games, but bear in mind it’s not intended to.
In your case, you should be using sprites or a tilemaps or sprites. As long as your atlas is containing all the variations you need (and it should be able to with good margin), you won’t break batching.
tilemap.set_tile() or changing the texture animation frame (using an atlas) is two good approaches in your case.
thank you for your explain. I think about sprites , but gui looks better for my idea. Because i don’t know how much colors i need. So changing color is what i need.
You can tint sprites too, but it will break batching. This could be fixed by setting the Z of your coloured sprites. E.g. Setting sprite.z = (color.r+color.g+color.b)*0.1
or something like it.
So if I set same z value for same colors, it will not break batching? Sprites my favorite now
Another approach is to have a single sprite, and overwrite its texture, as show in the example code for resource.set_texture()
Note that changing all pixels one by one in a large texture (e.g. full screen texture) from Lua is demanding, so you have to determine if it’s feasible for your project. AN alternative is to fill the pixels from a native extension.
Yes, if your tinted sprites have exactly the same tint they will batch together, but if they are only a tiny bit off they will not batch. So a color of (0.5, 0.5, 0.5, 1) and (0.51, 0.5, 0.5, 1) will NOT batch. They have to be identical. Remember that each unique tint will get its own batch, if you have 10 different tints you will get 10 batches. If you have 100 you will get 100 batches.
You can read some more about draw calls and batching in the post draw calls and defold.
I want to remind you again on what I am saying in my previous post: Using tilemaps, changing a tile with tilemap.set_tile() or using sprites changing animation frame from atlas using sprite atlas animation with a single, non-looping frame Sprite reference (animation) will NOT break batching. They only change the UV-coordinates which are sent with the sprite or tilemap vertices.
These two ways of doing what you want it by measures the cheapest way to achieve what you want to do.
I don’t need texture, while I only need to change color. I not sure how much color I will have. Because if I want to make a transition, from one color, to other, it will be a lot of different colors.
In the case of transition, I’d suggest you do textures of the colors you need and use what Mattias suggested with changing the z-value which you can act on in the shader.
Otherwise, using the gui is of course fine, but you’re stuck on 1024 nodes.
This is a very good suggestion. I would probably do it this way if I were to try and recreate a LED matrix like in your screenshot. I’d also back it by a native extension and only pass a Lua table with the LED matrix state and let the extension generate the actual pixels.
Yes, this is the best way. It have some question, how to draw one led. Is I need one size texture for all phones, or use screen size texture. Also it is take a time to write such native extension I am now prototyping, so I will use gui, because it is easy. But for production, changing one texture sounds very good.
No need for a native extension if all you want is to change a few pixels (as I imagine is all you need for a led)
To answer your question regarding texture size, you should use texture large enough so it can keep your entire led matrix without being scaled when rendered. You should scale the actual led graphics when rendering it instead.
If the 2D texture is scaled when rendering, you will either get a jagged or blurry result (depending on your sampling mode). I’m under the impression you’re looking for a 1:1 result of what you rendered given you won’t use texturing for your leds.
Also, some mobile hardware accepts only square power of two size textures, so if you intend this to be your final production solution, you’re best off creating a square texture with the size being the max size of width or height of the matrix.
While rendering to a texture might seem like a quick solution, it quickly gets complicated give different resolutions and even worse if you eventually decide to use textures for the leds.
My personal preferred solution is what Mattias Hedberg suggested above. Use the z-component of the sprites for coloring. That’s a quick solution and it won’t break batching.