How to "merge" sprites in defold

at left-bottom you can also see the grey text by myself showing just a couple of: items (GO), units (GO), structures (GO), deco like trees (GO)

/EDIT:
I got 42 draw calls…

OMG…
After opening a unit-menu…142 o.O

The menu is a dynamicly created menu based on a GUI “template” containing a 1 box-node, 1 spite, 2 text (2 fonts)
the 3 buttons around the unit are GUI boxes with sprite/graphics.
The info-box right-botton is GUI-box-node with graphic and text-node

HTML5 temporary test:

http://root.trinium.de/AbandonedForceDEMO/

Use F9/F10 for debug.

If I see the “iron”-item moving up and down I see how slow it works just from the start. normally it goes faster and smoother

/EDIT:
If you just click a unit (some squares with icons appear like moving, suicide etc) the draw-call jumps from 42 to 124 o.O

I quess there is a litte “optimisation” needed LOOOL

Back to the topic … I quess the main question was answered. Will testing which way may be the best a) 1 GO with 2 or more sprites, b) Collection with 2 or more GO or c) spines. Maybe collections will be a good way so every “part” will be a GO and together it will be a unit, structure etc. So I can change rotations etc.
Having a base with a rotating radar for example which is a collection. Or a tank with tracks facing to different angles etc.

Is it possible to deactivate a GO in a collection or changing its sprite?

Sure. Most components can be disabled, just send a “disable” message to the game object and its components will be disabled.

Yes, you can play animations on the sprites to change the graphics - as long as the animation is within the same atlas.

Ow, 142 draw calls, that’s a bit too many I’d say. I’m sure there are ways to reduce the number of draw calls to less than 20 in your game. Please read up on how the engine batches draw calls and what you can do to help the engine to reduce draw calls:
Draw calls and Defold

2 Likes

I already know how to disable etc. Just needed to know if its possible with collections.

Thanks!

Collections have no impact on a game object at all. They are a means of organizing game objects. They do not exist as a concept in runtime.

1 Like

First step (maybe interesting for beginners like me)…

ON top there is a statistic window. Used 3 atlasses in the past (units, structures, ingameGUI).
I’ve made a new atlas with all used graphics.
Changed the statistic graphics and set up just ONE atlas and changed the linked graphics of cause.

DrawCalls past: 42
DrawCalls now: 40

Sure, small result, but anyway, shows me how things take effect.
Will now change all Sprites to the new atlas.

Second try:

Removed unused graphics in GUI with boxes, sprites etc.

The “unit-menu” dropped from 124 to 107 frames. Logic… there was the “old” menu etc outof the view and other crap. Removed it to drop down the drawcalls. Have to continue the cleanup.

(btw, just posting this for beginners to prevent questions).

Maybe there should be another optimisation-thread?

@stephenkalisch I suggest you have a look at this great writeup on draw calls in defold by @Mattias_Hedberg to get you started :slight_smile:

3 Likes

My experience of optimisations.
This post awesome!

The main things that helped me:

  • use 1x1 alpha sprite in gui instead of empty nodes;
  • node layers;
  • replace tinting sprites with pre tined textures.
3 Likes

Thanks @AGulev.

I’ve seen your post already. Not sure how it works.
1x1 alpha sprite? I’ve added a 1x1 colored pixel, f.e. orange and added the texture for the box-node. but it “fades out”. Like you can see here (first button START)

Ah now… you mean for empty nodes. Dont have any yet. Tying your example I realized: textured boxes reduces the drawcalls by 1 instead of just colored boxes o.O

added a simple layer and added all nodes to it. no effect.

last point “tinting sprites” not sure what you mean…

btw: Very nice game you are on! Really like the graphics :wink:

1 Like

step by step:

  1. 1x1
    Sometimes you need empty node for right position of children.
    Bad a node without texture (break a batch) open full image by click:

Good (alpha texture should be in the same atlas as other gui items):

2 . Node layers
Different types of nodes break batch.

Bad when all nodes has the same layer or has no layer. All nodes draw one by one like in yours “Outline window” and if some text (for example) into box node, it will break batch.

Good all different types of node has own layer (draw order). For example all box nodes has an “img” layer, and all text node has “txt” layer. Sometimes you need to draw text under the box node, then you need one more layer for it.

3 . Tinting sprites.
If you change tint using sprite.set_constant, and it will be static (it is not an animation, just change tint once) You can change tint in photoshop and use this texture in game. It will help to reduce drawcalls count.

Ok. got the layers (always 2: one for boxes called “img” and one for the text-nodes called “txt”). changed on (hopefully) every gui.

Reduces the drawcalls by half! In the main menu there was 38 calls, now 23. In game (no building menus open), at 23 drawcalls, was 42.

Have to continue optimizing. Opening a unit-menu for building punshes the drawcalls from 23 to 90.
The reason is the dynamicly generated “pop-up-build-menu”.

Here…a question to @britzl and the other Pro’s… If I clone a node-tree, does the cloned one also clones the layer-config from the template? Or do I have to set it for the clones?

3 Likes

Does using GUI templates impact to the draw-calls?

I am using linked GUIs: unitmenu and buildmenu.

hm…
I dont know why the unit and structure menu takes about 70 drawcalls for 90 nodes.

both menues are now based on 2 layers.

Are you changing the color of the nodes? That would break the batches. Does all of the box nodes have an image assigned from the same texture?

hm…
I use box-nodes with different colors. I thought this would be the most “hardware-friendly” way (and I like simple looks).
All the dynamic (cloned) buttons have a coloured box as background. its about 15 buttons containing a background box-node, a box-node with a sprite and 2 text-nodes with 2 different fonts (sizes).

The content of the “ingameGUI” which will be activated after clicking on a unit or structure which takes about these 70 are in the last screenshot. The button left top is a template. it will be cloned depending on a table content which is actually 8 entries.
there is also a nearly same GUI (for structures)- dont have these small buttons in the middle - rest the same. also 7 dynamic buttons.

These 2 GUIs activated (happens if you click on unit OR structure) takes all the performance.

I could give you screens, source or access if you like.

I’ve saw this kind of solving and handling in some examples and thought it would be a good way.
Maybe I should handle it all in one GUI (unit and structure).
I have a couple of GUIs actually.

I was wrong. Box nodes with different colors does not break the batch. Sorry about that.

You’re welcome to invite me (bjorn.ritzl@king.com) to the project and I’ll take a look.