A collection of useful general resources made ready to be used with the Defold game engine
The purpose of this resource collection is to help speed up workflows for new projects, and help new users to learn useful techniques.
The license for the files included are CC0 1.0 Universal unless otherwise noted.
Installation
You can use DefRS in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add:
Once installed, you can use the resources you wish to use from their associated folders much like you would builtin resources. When you make builds Defold will only package the files you actually use so do not worry about the extra files included. Check your build folder to see for yourself.
Check the source files and examples for full usage.
This is sort of a continuation of Pro Tips plus a bunch of other resources I’ve prepared in the past. I’ll be updating it over time with lots of useful goodies! Like usual if you would like to be a contributor just ask and I’ll add you, if you want to contribute something send me a zip and I’ll add what works or do a pull request.
The shimmering and apparent lengthening of the attachments when they become flat isn’t intentional, not sure the cause but I vaguely remember that kind of thing happening in a past dev project with a different engine. But also may be a Defold bug.
Edit: shimmering was caused by the attachments not having a material set with a sampler. This version is fixed.
Added a colors library module! With it getting and setting colors in your scripts is a little more convenient. It also has a random color function, and a # hex color to rgba normalized function built into it.
Example usage
local colors = require("defrs.utils.colors")
function init(self)
pprint(colors.red)
pprint(colors.get_random_color())
self.timer = 0
self.step = 1
end
function update(self, dt)
self.timer = self.timer + dt
if self.timer > 1 then
self.timer = self.timer - 1
self.step = self.step + 1
if self.step == 4 then
self.step = 1
end
end
if self.step == 1 then
go.set("#label","color",colors.red)
elseif self.step == 2 then
go.set("#label","color",colors.magenta)
elseif self.step == 3 then
go.set("#label","color",colors.get_random_color())
end
end
I’ll add more color names to it over time so you can reasonably give any common name for a color and get its vec4 values formatted correctly for use.
Added a hue shift function that will take any vec4 color and shift it by a amount so you can shift over time or for whatever reason you might have. It’s possible to do things such as fade between two nearby hues.
Added 864 more colors from a batch process and realized I probably shouldn’t make so many vmath.vector4s? Todo will be to make it a meta table and return the vec4s as they are needed.
Identicons can be used as temporary avatars. You could increase the number of layers, and have some layers with transparent shapes to generate more detailed avatars.
Using an RNG method such as Mersenne Twister would be in improvement.
! Is this really useful? Having 10-20 predefined colors might be, but 864? I don’t think anyone goes “Hmm, I think I want international_orange_golden_gate_bridge for this text” (and yes, that’s actually one of the colors generated in the file).
You’re right - I’ll prune it down to a reasonable amount! The idea was more that you could type any common word for a color and actually get a match but many of them have non-intuitive names. Also going to make an html page that can be opened for a quick color key.
Do bmfonts work for you in editor 2? I tried making some and couldn’t get them to work
It could be adapted to detect any typed cheat code. A gesture version could be added too. A problem with it is that unless you have all keys added to your input file then it’s easier to not mess up the cheat codes you do detect.
Working on this example right now. Meant to show moving by vectors, and with a gameplay idea of a space shooter with gravity. So you must survive, shoot things, and fly against the pull of the sun.
Could be made into a fun game where all you are doing is trying to survive as long as possible while avoiding the sun / other things floating through space.
I hope eventually some people get inspired to take the basic ideas and iterate them into full games! I’ll add q and e for strafing sometime soon. Later today I’ll make some examples working with bezier curves.
Today working on making a shooter example with autotiles. So you draw the tiles with a solid tile and when the game loads it automatically sets the correct tile based on neighbors.
I’m really looking forward to user plugins too! There are so many kinds of plugins other tools have which would be super useful for Defold to have…
Working on random level generation at the moment. This is where in engine autotile will be really useful for procedurally generated and destructible level layouts!
Demo for random level. Click to get another random layout. At this size, it takes a moment. The method is very brute force and not optimized! Interesting that on Windows build it is much faster than HTML5 build. Probably modifying a table and then applying it to a tilemap would be much faster too rather than doing a ton of tilemap lookups? Probably would want to use fewer steps with this method, and then do multiple passes of multiplying the scale of the generated map and adding random changes to it such as making certain areas in to rooms / placing premade chunks / detecting features you don’t want to appear and changing them / adding doodads and loot / mobs …