imageslicegodotgdscript

How to Crop a image using gdscript in Godot?


I am making a game in Godot and took a 2d Sprite sheet with lots of pictures in it and I wanted those pictures to be cropped accordingly and store them in an array so I can use them later, But the problem is that Godot has no function that crops the image acc to given Rect2 prams,

so, please Help out.


Solution

  • If you are working with sprites and you have a sprite sheet. You can configure the Hframes and Vframes of your Sprite node to match the rows and columns of your sprite sheet. Then specify what sprite you want using the frame property.

    Alternatively, you can use a CanvasItem node (any Control or Node2D, including Sprite) and use draw_texture_rect to draw only a portion of a texture on it.

    Other options include a custom shader, and using C# to manipulate images. However, assuming you want sprites, the above should suffice.