Creating textures and scaling in Defold (SOLVED)

So, two things.

First, how do you instantiate a texture at runtime? Do you have to do it through a gui and if so, how do you know it’s id? Is it just the name of the file? I have a lose screen I want to create when the player… well, you know.

Second, I noticed the when I run my game and change the size of the window through defold, everything else scales with it. Does defold handle scaling for everything? I have a lot of gameobjects instantiated at specific spots in the game world and I was wanted to know if I port this game to mobile or something would everything still be in the right place?

Hmm, do you mean to create a texture and dynamically generate it’s content? Or do you mean how do you show a game over screen with a predefined image? You mentioned a game over screen. This can be created as a gui scene attached to a game object that you can either put in a collection and load or spawn using a factory.

Yes, the default render script is defined to scale everything to fit the dimensions of the screen. This could mean that stuff gets stretched in a way that doesn’t retain the original aspect ratio. This can sometimes be ok, and sometimes you’d rather prefer to keep the original aspect ratio and show more of the game area or maybe you want black borders. It all depends on what you prefer and what works for you. If you don’t want automatic stretching of everything you need to look into a custom render script. I have an example of a render script that maintains a fixed aspect ratio.

When it comes to a gui there are even more options. Please refer to the GUI manual for available options.

I was thinking more along the lines of a predefined image but a scene would be nice too actually…

Ok, I mean if it’s only an image that you wish to show then why don’t you just add that image to an atlas, create a game object with a sprite that references the image in the atlas and enable it when you need to show it?

If you want something more advances I’d suggest that you create a gui with a box node that references the image in the atlas and enable it via a gui script when you need to show it or load the whole thing from a collection proxy.

Ooooo, a disable. Is there a way to disable objects through the inspector (I’m not sure what it’s called in defold) or do I have to call disable on that object in one of my scripts when I initialize?

No, there’s no way to disable a component from the editor itself. You need to post a message to it from a script.

Sweet, it works. Thanks for help again.