Big List of Defold Pro Tips!

Get current app version to display to your users.

sys.get_config("project.version")

There are many kinds of version number conventions. The way I prefer to do it with my games is 1.0.year.month.day.build so for example today’s would be 1.0.16.4.25 for the first build and 1.0.16.4.25.2 for the second build of the day. I’ve used other systems before but I like this one because you can see when the version was made live at a glance.

You can also use sys.get_config to get anything listed in the game.project file.

sys.get_config("project.title")
sys.get_config("display.width")
sys.get_config("physics.scale")

And so on.

5 Likes

If you are using Tiled to edit your Tilemaps and they’re big, you can quickly create the tilemap file in Defold like this:
Create a tilemap as usual and select the tile source. Select a tile and place it at the origin, then place another tile at a random place, such as 5,5. Save and close the tilemap.

Then in the Project Explorer, right click on the tilemap file and select open with Text Editor. You should see the 2 cell tables for the tiles you added. In the bottom cell set the x and y values of to be how many tiles high and wide your tilemap will be. If you have extra layers, add the values to that as well.

This should make your tilemap the right size for the import.
Well it worked for me :slight_smile:

1 Like

I’m not sure whether this feature flew under everyone’s radar or not, but we re-did the search mechanism a few weeks ago – enabling filtering of your search results. It’s also more liberal nowadays with displaying words inside of articles, etc. Don’t hesitate to PM me if you have any site feedback or find any bugs!

4 Likes

Do not worry this thread is not forever dead… after I finish the book I plan to continue posting more tips! I’ve been making many interesting discoveries and tricks that may not be immediately obvious and found some things which are usable but not documented at all!

4 Likes

Great. Please post any lacking documentation and we’ll fix that.

2 Likes

Demonstrating the various easing equations built in with how they work with go.animate

Working on this for the book. Run this example, and press up / down to go through the different easing equations. Then left click to animate the Defold logo to the new position. Ghosts of the Defold logo are created as it is repositioned by the animation to so the path clearly, and a white dot is left at the original position to more clearly show how some of the easing equations differ.

I plan to improve it, such as having a mode for the logo to move around randomly within the space after it completes each animation. Todo…

Web version: https://www.bookofdefold.com/examples/DefoldEasingEquations/

EasingEquations.zip (18.6 KB)

16 Likes

Nice! Thanks for sharing!

2 Likes

I just found this and it made my day - I’ve been trying to get the low-res font in Labyrinth to filter by nearest for a while and I put it on the back burner, now I can fix that!

2 Likes

f.lux will cause any Defold game (well, probably the entire screen) to stutter during the transition to “night shift”

2 Likes

Configuration settings retrieved with sys.get_config() are returned as string values; if you’re reading something that needs to be treated as a number (such as display height), use the Lua ‘tonumber’ function to convert the string into a number:

tonumber(sys.get_config("display.height"))
2 Likes

To get the size of a sprite that has been scaled, multiply the width/height by the sprite’s scale amount; for example:

local spriteWidth = go.get("#spriteAsteroid", "size.x") * go.get("#spriteAsteroid", "scale.x")
1 Like

There are a few issues with this snippet of code:

  1. You call it spriteWidth but you base it on size.y. It should either be spriteHeight or you should base it on sprite.x
  2. You are ignoring the sprite scale. You need to also use go.get("#spriteAsteroid", "scale.y")
  3. Sprites can be non uniformly scaled. I think you should multiply with go.get_scale_vector().y instead of go.get_scale()

I recently created an example of how to detect clicks on game objects with a sprite component and had to use to tale into account both scale of game object and of the sprite to get correct results.

5 Likes

Gosh darn it…sorry 'bout the typos, and thanks for the info in #3!

Correcting my original post now… :slight_smile:

Bryan

2 Likes

@Pkeod, did you ever finish your supersampling vs multisampling in Defold investigation? Any results to share?

I should revisit again sometime soon and do new tests as I did leave things unfinished. I wasn’t happy with the results for a 3D project I was testing and gave up for the time being.

Defold has SSAA built in. This is the samples option in the game.project file. Other methods have to be setup manually as post processing shaders - I can publish examples later, it would be handy to be able to be able to drop the different methods in/out quickly.

For 2D projects, these features are not really useful. For 3D projects they can be used to reduce things like jagged edges / aliasing. As Defold’s 3D features improve, then they will be more relevant for more projects depending on the needs of an individual project. For now, it’s not a topic worth too much time.

If you do have a 2D game with jagged edges for example when rotating an object make sure you add enough inner padding to the sprites. If your image has image data near the edges of the image container then it’s more likely those edges will look bad when rotating.

Generally super sampling is better but more costly. The other methods are optimized approximations meant for specific situations with pros/cons each.

AA features are generally not appropriate for mobile games as they are costly. Unless you know you are only targeting devices such as the newest iPads then it’s safer to use. Defold doesn’t allow you to control the samples at runtime yet.

4 Likes

I have published my game code on GitHub - https://github.com/baturinsky/GlueTime

You can check it if you want to see how to

  1. Write parts of 2d physics that are missing in vanilla Defold, such is dynamically changing rigid bodies. See lib/rigid.lua and lib/collider.lua specifically.
  2. Scale time (set_time_step in lib/global.lua) and view (main/my.render_script, look for word “zoom”).
  3. And many other more trivial things that someone could find not quite trivial.

Speaking of physics, if someone is wanting to delve in it, two advices. First, read this http://chrishecker.com/images/e/e7/Gdmphys3.pdf for the basic math of it - it’s most to-the-point article I have found. Second - don’t apply changes to position, speed, rotation etc right when you calculate them. It can screw further calculations, especially one with the other body that is involved in same collision. Instead, accumulate changes and apply them after all collision calculations in current frame are done.

12 Likes

Nice. Thank you for sharing @baturinsky!

2 Likes

Enums
If you want to use enums instead of custom strings you can do this:

BLOCK_TYPES = {
    red = 0,
    blue = 1,
    gold = 2
}

Using:

local new_block = ....
new_block.type = BLOCK_TYPES.red
7 Likes

Did a custom shader library ever get created? I am looking for either a glow or blur, possibly both.

1 Like

No, I don’t think anyone created one I’m afraid…