0 votes

Scaling down.

Have image(png - size 500x500) for object's sprite(size 20x20).

I used scale ration 0.04 on object's sprite but that effected how physics are applied to object later in game. So i don't want that.

1.How to export and save object's sprite image while game is running as .png?
2.Why are images that are scaled by other image editors when imported in godot blurry, but when i directly in godot scale them down, they are not?

I have seen that godot does a good job with scaling down (no blurry result) as opposed to paint or many other scaling down applications on internet.

Further reading:
I have been trying for whole day in Java to scale down image, and:
I just can't understand why i couldn't convert DataBufferByte to DataBufferInt


f = new File("pic1.png");
 image_i = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
 image_i = ImageIO.read(f);
int[] pixels = ((DataBufferInt) image_i.getRaster().getDataBuffer()).getData(); 


java.lang.ClassCastException: java.awt.image.DataBufferByte cannot be cast to java.awt.image.DataBufferInt

I have also tried to implement scaling algorithm, as it can be seen here:

but this exception is stopping me.

in Engine by (65 points)
edited by

For physics mentioned above, I had a bug in code. Physics are good. It was about some calculations for width and height of sprite.

1 Answer

+1 vote
  1. You can use Image.save_png() http://docs.godotengine.org/en/3.1/classes/class_image.html?highlight=save_png#class-image-method-save-png
    Note: this is an Image method, so you need an Image (not a Texture, not a Sprite).

  2. They are blurry when imported maybe because you left the filter option on in the import settings. Double-click on your texture, uncheck the filter checkbox and click "Reimport". You can save the config as default using the "Preset..." menu.

Also depending on what you really want to do, you might just need to make your image 20x20 in the first place so you don't need to scale down?

I used scale ration 0.04 on object's sprite but that effected how physics are applied to object later in game. So i don't want that.

Then you could have the sprite as child of the body, and scale down ONLY the sprite?

by (28,882 points)


 var image = get_node("sprite").get_texture().get_data();

but it saves a blurry image.

  1. I found option for filter, disabled him, and then clicked reimport, but nothing changed.
    3. I have sprite as a child of the body, and in whole this story i'm scaling sprite not the parent (Area2D) but somehow this scaling have impact on Area2D pyhsics.
  2. It is a lot easier to draw picture on canvas 500x500 then on 20x20.

I wonder what are you trying to achieve in the first place?
In the code you pasted you basically told Godot to upload the texture to the graphics card, then download it back, then resize it and save it as a file... but why?

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.