We will release a new feature called resource properties in Defold 1.2.163. It has been hinted at many times on the forum and now it’s finally time to release it! Resource properties expands on the existing script properties system and it allows you to define a new set of script properties that can be used to reference resources. Most of you are probably familiar with this:
go.property("hostile", true)
go.property("speed", 42)
go.property("direction", vmath.vector3(1, 0.3, 0.0))
go.property("color", vmath.vector4(1.0, 1.0, 0.0, 0.5))
go.property("attack", hash("slash"))
go.property("trigger", msg.url("some:/other#system"))
New script property types are:
go.property("jungle", resource.tile_source())
go.property("glow", resource.material())
go.property("alert", resource.font())
go.property("light", resource.texture())
go.property("weapons", resource.atlas())
They will show up in the properties panel as resource fields where you can browse for the specific resource type among your project assets:
You use them like this:
-- change sprite, tilemap, model, spinemodel and gui material
go.set("#sprite", "material", self.glow)
go.set("#tilemap", "material", self.glow)
go.set("#model", "material", self.glow)
go.set("#spinemodel", "material", self.glow)
go.set("#gui", "material", self.glow)
-- change sprite image
go.set("#sprite", "image", self.jungle)
go.set("#sprite", "image", self.weapons)
-- change tilemap tilesource
go.set("#tilemap", "tile_source", self.jungle)
-- change label font
go.set("#label", "font", self.alert)
-- change model texture
go.set("#model", "texture0", self.light)
If you’d like to play around with this feature before release it is available on the alpha channel:
- macOS - https://d.defold.com/archive/1eb61acc7a8ca622bedb5bf862ddbf44bfb95727/alpha/editor2/Defold-x86_64-darwin.dmg
- Linux - https://d.defold.com/archive/1eb61acc7a8ca622bedb5bf862ddbf44bfb95727/alpha/editor2/Defold-x86_64-linux.zip
- Windows - https://d.defold.com/archive/1eb61acc7a8ca622bedb5bf862ddbf44bfb95727/alpha/editor2/Defold-x86_64-win32.zip