+1 vote

Hello,
I have just migrated from libgdx and trying to learn godot. One thing which I am not able to do or did not find any resources online is how to use different assets source. For eg, in libgdx i had three different file of same texture but with different size. That way i would not need to scale up or down (results in smooth graphics overall) and just render it to viewport. I first queried screen size,and point the asset loader to the specific location while loading, some thing like this

ResolutionFileResolver.Resolution[] resolutions = {
new ResolutionFileResolver.Resolution(720, 1280, "1280X720"),
new ResolutionFileResolver.Resolution(1080, 1920, "1920X1080"),
new ResolutionFileResolver.Resolution(1440,2560, "2560X1440")
};

    ResolutionFileResolver resolver = new ResolutionFileResolver(new InternalFileHandleResolver(),resolutions);
    assetManager = new AssetManager();
    assetManager.setLoader(TextureAtlas.class,new TextureAtlasLoader(resolver));

Is it possible to simulate it in godot? Basically I want the sprite to pick up texture source based on the screen size.

in Engine by (18 points)

In Godot use mip maps for the same effect, but only when using the Display->Window->Stretch->Mode = 2D option under Project Settings.

Godot's 2D stretch mode is what you are use to from libgdx
When clicking on a image, go to it's import settings and accept the Mipmap flag, then re-import.
Mip maps are made by the computer from your largest image, it calculates all the smaller versions for you and you don't have to make them yourself.

Godot also has a Viewport mode, this will scale the image for you at realtime. You won't need smaller version of the image to do this.

1 Answer

0 votes

You could probably do something like this.

var texture_path = "res://examples/texture-"
var texture
var screen_size = get_viewport.size
if screen_size.y >= 2160: #4K
    texture = preload(texture_path+"-4K.png")
elif screen_size.y >= 1080: #FullHD
    texture = preload(texture_path+"-FullHD.png")
elif screen_size.y >= 720: #HD(720p)
    texture = preload(texture_path+"-HD.png")
else: #480p or less. The lowest resolution
    texture = preload(texture_path+".png")

Just be sure to name your textures properly like-

  • texture-4k.png
  • texture-fullHD.png
  • texture-HD.png
  • texture.png
by (3,928 points)

I think this approach is just a hack. It becomes tedious when project size increases. I was looking for something which automatically switches asset location. The above approach also forces you to build the ui from code rather than from editor.
Thanks for suggestion

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.