Struct Image
pub struct Image { /* private fields */ }Expand description
Godot class Image.
Inherits Resource.
Related symbols:
See also Godot docs for Image.
§Construction
This class is reference-counted. You can create a new instance using Image::new_gd().
§Godot docs
Native image datatype. Contains image data which can be converted to an ImageTexture and provides commonly used image processing methods. The maximum width and height for an Image are MAX_WIDTH and MAX_HEIGHT.
An Image cannot be assigned to a texture property of an object directly (such as [member Sprite2D.texture]), and has to be converted manually to an ImageTexture first.
Note: Methods that modify the image data cannot be used on VRAM-compressed images. Use decompress to convert the image to an uncompressed format first.
Note: The maximum image size is 16384×16384 pixels due to graphics hardware limitations. Larger images may fail to import.
Implementations§
§impl Image
impl Image
pub const MAX_WIDTH: i32 = 16777216i32
pub const MAX_HEIGHT: i32 = 16777216i32
pub fn get_height(&self) -> i32
pub fn get_height(&self) -> i32
Returns the image’s height.
pub fn has_mipmaps(&self) -> bool
pub fn has_mipmaps(&self) -> bool
Returns true if the image has generated mipmaps.
pub fn get_format(&self) -> Format
pub fn get_format(&self) -> Format
Returns this image’s format.
pub fn get_data(&self) -> PackedArray<u8>
pub fn get_data(&self) -> PackedArray<u8>
Returns a copy of the image’s raw data.
pub fn get_data_size(&self) -> i64
pub fn get_data_size(&self) -> i64
Returns size (in bytes) of the image’s raw data.
pub fn get_mipmap_count(&self) -> i32
pub fn get_mipmap_count(&self) -> i32
Returns the number of mipmap levels or 0 if the image has no mipmaps. The largest main level image is not counted as a mipmap level by this method, so if you want to include it you can add 1 to this count.
pub fn get_mipmap_offset(&self, mipmap: i32) -> i64
pub fn get_mipmap_offset(&self, mipmap: i32) -> i64
Returns the offset where the image’s mipmap with index mipmap is stored in the [member data] dictionary.
pub fn resize_to_po2(&mut self)
pub fn resize_to_po2(&mut self)
To set the default parameters, use resize_to_po2_ex and its builder methods. See the book for detailed usage instructions.
Resizes the image to the nearest power of 2 for the width and height. If square is true, sets width and height to be the same. New pixels are calculated using the interpolation mode defined via [enum Interpolation] constants.
pub fn resize_to_po2_ex<'ex>(&'ex mut self) -> ExResizeToPo2<'ex>
pub fn resize_to_po2_ex<'ex>(&'ex mut self) -> ExResizeToPo2<'ex>
Resizes the image to the nearest power of 2 for the width and height. If square is true, sets width and height to be the same. New pixels are calculated using the interpolation mode defined via [enum Interpolation] constants.
pub fn resize_ex<'ex>(&'ex mut self, width: i32, height: i32) -> ExResize<'ex>
pub fn resize_ex<'ex>(&'ex mut self, width: i32, height: i32) -> ExResize<'ex>
Resizes the image to the given width and height. New pixels are calculated using the interpolation mode defined via [enum Interpolation] constants.
pub fn shrink_x2(&mut self)
pub fn shrink_x2(&mut self)
Shrinks the image by a factor of 2 on each axis (this divides the pixel count by 4).
pub fn crop(&mut self, width: i32, height: i32)
pub fn crop(&mut self, width: i32, height: i32)
Crops the image to the given width and height. If the specified size is larger than the current size, the extra area is filled with black pixels.
pub fn flip_x(&mut self)
pub fn flip_x(&mut self)
Flips the image horizontally.
pub fn flip_y(&mut self)
pub fn flip_y(&mut self)
Flips the image vertically.
pub fn generate_mipmaps(&mut self) -> Error
pub fn generate_mipmaps(&mut self) -> Error
To set the default parameters, use generate_mipmaps_ex and its builder methods. See the book for detailed usage instructions.
Generates mipmaps for the image. Mipmaps are precalculated lower-resolution copies of the image that are automatically used if the image needs to be scaled down when rendered. They help improve image quality and performance when rendering. This method returns an error if the image is compressed, in a custom format, or if the image’s width/height is 0. Enabling renormalize when generating mipmaps for normal map textures will make sure all resulting vector values are normalized.
It is possible to check if the image has mipmaps by calling has_mipmaps or get_mipmap_count. Calling generate_mipmaps on an image that already has mipmaps will replace existing mipmaps in the image.
pub fn generate_mipmaps_ex<'ex>(&'ex mut self) -> ExGenerateMipmaps<'ex>
pub fn generate_mipmaps_ex<'ex>(&'ex mut self) -> ExGenerateMipmaps<'ex>
Generates mipmaps for the image. Mipmaps are precalculated lower-resolution copies of the image that are automatically used if the image needs to be scaled down when rendered. They help improve image quality and performance when rendering. This method returns an error if the image is compressed, in a custom format, or if the image’s width/height is 0. Enabling renormalize when generating mipmaps for normal map textures will make sure all resulting vector values are normalized.
It is possible to check if the image has mipmaps by calling has_mipmaps or get_mipmap_count. Calling generate_mipmaps on an image that already has mipmaps will replace existing mipmaps in the image.
pub fn clear_mipmaps(&mut self)
pub fn clear_mipmaps(&mut self)
Removes the image’s mipmaps.
pub fn create(
width: i32,
height: i32,
use_mipmaps: bool,
format: Format,
) -> Option<Gd<Image>>
pub fn create( width: i32, height: i32, use_mipmaps: bool, format: Format, ) -> Option<Gd<Image>>
Creates an empty image of the given size and format. If use_mipmaps is true, generates mipmaps for this image (see generate_mipmaps).
pub fn create_empty(
width: i32,
height: i32,
use_mipmaps: bool,
format: Format,
) -> Option<Gd<Image>>
pub fn create_empty( width: i32, height: i32, use_mipmaps: bool, format: Format, ) -> Option<Gd<Image>>
Creates an empty image of the given size and format. If use_mipmaps is true, generates mipmaps for this image (see generate_mipmaps).
pub fn create_from_data(
width: i32,
height: i32,
use_mipmaps: bool,
format: Format,
data: &PackedArray<u8>,
) -> Option<Gd<Image>>
pub fn create_from_data( width: i32, height: i32, use_mipmaps: bool, format: Format, data: &PackedArray<u8>, ) -> Option<Gd<Image>>
Creates a new image of the given size and format. Fills the image with the given raw data. If use_mipmaps is true, loads the mipmaps for this image from data. See generate_mipmaps.
pub fn set_data(
&mut self,
width: i32,
height: i32,
use_mipmaps: bool,
format: Format,
data: &PackedArray<u8>,
)
pub fn set_data( &mut self, width: i32, height: i32, use_mipmaps: bool, format: Format, data: &PackedArray<u8>, )
Overwrites data of an existing Image. Non-static equivalent of create_from_data.
pub fn load(&mut self, path: impl AsArg<GString>) -> Error
pub fn load(&mut self, path: impl AsArg<GString>) -> Error
Loads an image from file path. See Supported image formats for a list of supported image formats and limitations.
Warning: This method should only be used in the editor or in cases when you need to load external images at run-time, such as images located at the user:// directory, and may not work in exported projects.
See also ImageTexture description for usage examples.
pub fn load_from_file(path: impl AsArg<GString>) -> Option<Gd<Image>>
pub fn load_from_file(path: impl AsArg<GString>) -> Option<Gd<Image>>
Creates a new Image and loads data from the specified file.
pub fn save_png(&self, path: impl AsArg<GString>) -> Error
pub fn save_png(&self, path: impl AsArg<GString>) -> Error
Saves the image as a PNG file to the file at path.
pub fn save_png_to_buffer(&self) -> PackedArray<u8>
pub fn save_png_to_buffer(&self) -> PackedArray<u8>
Saves the image as a PNG file to a byte array.
pub fn save_jpg(&self, path: impl AsArg<GString>) -> Error
pub fn save_jpg(&self, path: impl AsArg<GString>) -> Error
To set the default parameters, use save_jpg_ex and its builder methods. See the book for detailed usage instructions.
Saves the image as a JPEG file to path with the specified quality between 0.01 and 1.0 (inclusive). Higher quality values result in better-looking output at the cost of larger file sizes. Recommended quality values are between 0.75 and 0.90. Even at quality 1.00, JPEG compression remains lossy.
Note: JPEG does not save an alpha channel. If the Image contains an alpha channel, the image will still be saved, but the resulting JPEG file won’t contain the alpha channel.
pub fn save_jpg_ex<'ex>(
&'ex self,
path: impl AsArg<GString> + 'ex,
) -> ExSaveJpg<'ex>
pub fn save_jpg_ex<'ex>( &'ex self, path: impl AsArg<GString> + 'ex, ) -> ExSaveJpg<'ex>
Saves the image as a JPEG file to path with the specified quality between 0.01 and 1.0 (inclusive). Higher quality values result in better-looking output at the cost of larger file sizes. Recommended quality values are between 0.75 and 0.90. Even at quality 1.00, JPEG compression remains lossy.
Note: JPEG does not save an alpha channel. If the Image contains an alpha channel, the image will still be saved, but the resulting JPEG file won’t contain the alpha channel.
pub fn save_jpg_to_buffer(&self) -> PackedArray<u8>
pub fn save_jpg_to_buffer(&self) -> PackedArray<u8>
To set the default parameters, use save_jpg_to_buffer_ex and its builder methods. See the book for detailed usage instructions.
Saves the image as a JPEG file to a byte array with the specified quality between 0.01 and 1.0 (inclusive). Higher quality values result in better-looking output at the cost of larger byte array sizes (and therefore memory usage). Recommended quality values are between 0.75 and 0.90. Even at quality 1.00, JPEG compression remains lossy.
Note: JPEG does not save an alpha channel. If the Image contains an alpha channel, the image will still be saved, but the resulting byte array won’t contain the alpha channel.
pub fn save_jpg_to_buffer_ex<'ex>(&'ex self) -> ExSaveJpgToBuffer<'ex>
pub fn save_jpg_to_buffer_ex<'ex>(&'ex self) -> ExSaveJpgToBuffer<'ex>
Saves the image as a JPEG file to a byte array with the specified quality between 0.01 and 1.0 (inclusive). Higher quality values result in better-looking output at the cost of larger byte array sizes (and therefore memory usage). Recommended quality values are between 0.75 and 0.90. Even at quality 1.00, JPEG compression remains lossy.
Note: JPEG does not save an alpha channel. If the Image contains an alpha channel, the image will still be saved, but the resulting byte array won’t contain the alpha channel.
pub fn save_exr(&self, path: impl AsArg<GString>) -> Error
pub fn save_exr(&self, path: impl AsArg<GString>) -> Error
To set the default parameters, use save_exr_ex and its builder methods. See the book for detailed usage instructions.
Saves the image as an EXR file to path. If grayscale is true and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return Error::ERR_UNAVAILABLE if Godot was compiled without the TinyEXR module.
pub fn save_exr_ex<'ex>(
&'ex self,
path: impl AsArg<GString> + 'ex,
) -> ExSaveExr<'ex>
pub fn save_exr_ex<'ex>( &'ex self, path: impl AsArg<GString> + 'ex, ) -> ExSaveExr<'ex>
Saves the image as an EXR file to path. If grayscale is true and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return Error::ERR_UNAVAILABLE if Godot was compiled without the TinyEXR module.
pub fn save_exr_to_buffer(&self) -> PackedArray<u8>
pub fn save_exr_to_buffer(&self) -> PackedArray<u8>
To set the default parameters, use save_exr_to_buffer_ex and its builder methods. See the book for detailed usage instructions.
Saves the image as an EXR file to a byte array. If grayscale is true and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return an empty byte array if Godot was compiled without the TinyEXR module.
pub fn save_exr_to_buffer_ex<'ex>(&'ex self) -> ExSaveExrToBuffer<'ex>
pub fn save_exr_to_buffer_ex<'ex>(&'ex self) -> ExSaveExrToBuffer<'ex>
Saves the image as an EXR file to a byte array. If grayscale is true and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return an empty byte array if Godot was compiled without the TinyEXR module.
pub fn save_dds(&self, path: impl AsArg<GString>) -> Error
pub fn save_dds(&self, path: impl AsArg<GString>) -> Error
Saves the image as a DDS (DirectDraw Surface) file to path. DDS is a container format that can store textures in various compression formats, such as DXT1, DXT5, or BC7. This function will return Error::ERR_UNAVAILABLE if Godot was compiled without the DDS module.
Note: The DDS module may be disabled in certain builds, which means save_dds will return Error::ERR_UNAVAILABLE when it is called from an exported project.
pub fn save_dds_to_buffer(&self) -> PackedArray<u8>
pub fn save_dds_to_buffer(&self) -> PackedArray<u8>
Saves the image as a DDS (DirectDraw Surface) file to a byte array. DDS is a container format that can store textures in various compression formats, such as DXT1, DXT5, or BC7. This function will return an empty byte array if Godot was compiled without the DDS module.
Note: The DDS module may be disabled in certain builds, which means save_dds_to_buffer will return an empty byte array when it is called from an exported project.
pub fn save_webp(&self, path: impl AsArg<GString>) -> Error
pub fn save_webp(&self, path: impl AsArg<GString>) -> Error
To set the default parameters, use save_webp_ex and its builder methods. See the book for detailed usage instructions.
Saves the image as a WebP (Web Picture) file to the file at path. By default it will save lossless. If lossy is true, the image will be saved lossy, using the quality setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG.
Note: The WebP format is limited to a size of 16383×16383 pixels, while PNG can save larger images.
pub fn save_webp_ex<'ex>(
&'ex self,
path: impl AsArg<GString> + 'ex,
) -> ExSaveWebp<'ex>
pub fn save_webp_ex<'ex>( &'ex self, path: impl AsArg<GString> + 'ex, ) -> ExSaveWebp<'ex>
Saves the image as a WebP (Web Picture) file to the file at path. By default it will save lossless. If lossy is true, the image will be saved lossy, using the quality setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG.
Note: The WebP format is limited to a size of 16383×16383 pixels, while PNG can save larger images.
pub fn save_webp_to_buffer(&self) -> PackedArray<u8>
pub fn save_webp_to_buffer(&self) -> PackedArray<u8>
To set the default parameters, use save_webp_to_buffer_ex and its builder methods. See the book for detailed usage instructions.
Saves the image as a WebP (Web Picture) file to a byte array. By default it will save lossless. If lossy is true, the image will be saved lossy, using the quality setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG.
Note: The WebP format is limited to a size of 16383×16383 pixels, while PNG can save larger images.
pub fn save_webp_to_buffer_ex<'ex>(&'ex self) -> ExSaveWebpToBuffer<'ex>
pub fn save_webp_to_buffer_ex<'ex>(&'ex self) -> ExSaveWebpToBuffer<'ex>
Saves the image as a WebP (Web Picture) file to a byte array. By default it will save lossless. If lossy is true, the image will be saved lossy, using the quality setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG.
Note: The WebP format is limited to a size of 16383×16383 pixels, while PNG can save larger images.
pub fn detect_alpha(&self) -> AlphaMode
pub fn detect_alpha(&self) -> AlphaMode
Returns AlphaMode::BLEND if the image has data for alpha values. Returns AlphaMode::BIT if all the alpha values are stored in a single bit. Returns AlphaMode::NONE if no data for alpha values is found.
pub fn is_invisible(&self) -> bool
pub fn is_invisible(&self) -> bool
Returns true if all the image’s pixels have an alpha value of 0. Returns false if any pixel has an alpha value higher than 0.
pub fn detect_used_channels(&self) -> UsedChannels
pub fn detect_used_channels(&self) -> UsedChannels
To set the default parameters, use detect_used_channels_ex and its builder methods. See the book for detailed usage instructions.
Returns the color channels used by this image. If the image is compressed, the original source must be specified.
pub fn detect_used_channels_ex<'ex>(&'ex self) -> ExDetectUsedChannels<'ex>
pub fn detect_used_channels_ex<'ex>(&'ex self) -> ExDetectUsedChannels<'ex>
Returns the color channels used by this image. If the image is compressed, the original source must be specified.
pub fn compress(&mut self, mode: CompressMode) -> Error
pub fn compress(&mut self, mode: CompressMode) -> Error
To set the default parameters, use compress_ex and its builder methods. See the book for detailed usage instructions.
Compresses the image with a VRAM-compressed format to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available.
The source parameter helps to pick the best compression method for DXT and ETC2 formats. It is ignored for ASTC compression.
The astc_format parameter is only taken into account when using ASTC compression; it is ignored for all other formats.
Note: compress is only supported in editor builds. When run in an exported project, this method always returns Error::ERR_UNAVAILABLE.
pub fn compress_ex<'ex>(&'ex mut self, mode: CompressMode) -> ExCompress<'ex>
pub fn compress_ex<'ex>(&'ex mut self, mode: CompressMode) -> ExCompress<'ex>
Compresses the image with a VRAM-compressed format to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available.
The source parameter helps to pick the best compression method for DXT and ETC2 formats. It is ignored for ASTC compression.
The astc_format parameter is only taken into account when using ASTC compression; it is ignored for all other formats.
Note: compress is only supported in editor builds. When run in an exported project, this method always returns Error::ERR_UNAVAILABLE.
pub fn compress_from_channels(
&mut self,
mode: CompressMode,
channels: UsedChannels,
) -> Error
pub fn compress_from_channels( &mut self, mode: CompressMode, channels: UsedChannels, ) -> Error
To set the default parameters, use compress_from_channels_ex and its builder methods. See the book for detailed usage instructions.
Compresses the image with a VRAM-compressed format to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available.
This is an alternative to compress that lets the user supply the channels used in order for the compressor to pick the best DXT and ETC2 formats. For other formats (non DXT or ETC2), this argument is ignored.
The astc_format parameter is only taken into account when using ASTC compression; it is ignored for all other formats.
Note: compress_from_channels is only supported in editor builds. When run in an exported project, this method always returns Error::ERR_UNAVAILABLE.
pub fn compress_from_channels_ex<'ex>(
&'ex mut self,
mode: CompressMode,
channels: UsedChannels,
) -> ExCompressFromChannels<'ex>
pub fn compress_from_channels_ex<'ex>( &'ex mut self, mode: CompressMode, channels: UsedChannels, ) -> ExCompressFromChannels<'ex>
Compresses the image with a VRAM-compressed format to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available.
This is an alternative to compress that lets the user supply the channels used in order for the compressor to pick the best DXT and ETC2 formats. For other formats (non DXT or ETC2), this argument is ignored.
The astc_format parameter is only taken into account when using ASTC compression; it is ignored for all other formats.
Note: compress_from_channels is only supported in editor builds. When run in an exported project, this method always returns Error::ERR_UNAVAILABLE.
pub fn decompress(&mut self) -> Error
pub fn decompress(&mut self) -> Error
Decompresses the image if it is VRAM-compressed in a supported format. This increases memory utilization, but allows modifying the image. Returns Error::OK if the format is supported, otherwise Error::ERR_UNAVAILABLE. All VRAM-compressed formats supported by Godot can be decompressed with this method, except Format::ETC2_R11S, Format::ETC2_RG11S, and Format::ETC2_RGB8A1.
pub fn is_compressed(&self) -> bool
pub fn is_compressed(&self) -> bool
Returns true if the image is compressed.
pub fn rotate_90(&mut self, direction: ClockDirection)
pub fn rotate_90(&mut self, direction: ClockDirection)
Rotates the image in the specified direction by 90 degrees. The width and height of the image must be greater than 1. If the width and height are not equal, the image will be resized.
pub fn rotate_180(&mut self)
pub fn rotate_180(&mut self)
Rotates the image by 180 degrees. The width and height of the image must be greater than 1.
pub fn fix_alpha_edges(&mut self)
pub fn fix_alpha_edges(&mut self)
Blends low-alpha pixels with nearby pixels.
pub fn premultiply_alpha(&mut self)
pub fn premultiply_alpha(&mut self)
Multiplies color values with alpha values. Resulting color values for a pixel are (color * alpha)/256. See also [member CanvasItemMaterial.blend_mode].
pub fn srgb_to_linear(&mut self)
pub fn srgb_to_linear(&mut self)
Converts the raw data from nonlinear sRGB encoding to linear encoding using a lookup table. Only works on images with Format::RGB8 or Format::RGBA8 formats.
Note: The 8-bit formats required by this method are not suitable for storing linearly encoded values; a significant amount of color information will be lost in darker values. To maintain image quality, this method should not be used.
pub fn linear_to_srgb(&mut self)
pub fn linear_to_srgb(&mut self)
Converts the entire image from linear encoding to nonlinear sRGB encoding by using a lookup table. Only works on images with Format::RGB8 or Format::RGBA8 formats.
pub fn normal_map_to_xy(&mut self)
pub fn normal_map_to_xy(&mut self)
Converts the image’s data to represent coordinates on a 3D plane. This is used when the image represents a normal map. A normal map can add lots of detail to a 3D surface without increasing the polygon count.
pub fn rgbe_to_srgb(&mut self) -> Option<Gd<Image>>
pub fn rgbe_to_srgb(&mut self) -> Option<Gd<Image>>
Converts a standard linear RGBE (Red Green Blue Exponent) image to an image that uses nonlinear sRGB encoding.
pub fn bump_map_to_normal_map(&mut self)
pub fn bump_map_to_normal_map(&mut self)
To set the default parameters, use bump_map_to_normal_map_ex and its builder methods. See the book for detailed usage instructions.
Converts a bump map to a normal map. A bump map provides a height offset per-pixel, while a normal map provides a normal direction per pixel.
pub fn bump_map_to_normal_map_ex<'ex>(
&'ex mut self,
) -> ExBumpMapToNormalMap<'ex>
pub fn bump_map_to_normal_map_ex<'ex>( &'ex mut self, ) -> ExBumpMapToNormalMap<'ex>
Converts a bump map to a normal map. A bump map provides a height offset per-pixel, while a normal map provides a normal direction per pixel.
pub fn compute_image_metrics(
&mut self,
compared_image: impl AsArg<Option<Gd<Image>>>,
use_luma: bool,
) -> Dictionary<Variant, Variant>
pub fn compute_image_metrics( &mut self, compared_image: impl AsArg<Option<Gd<Image>>>, use_luma: bool, ) -> Dictionary<Variant, Variant>
Compute image metrics on the current image and the compared image. This can be used to calculate the similarity between two images.
The dictionary contains max, mean, mean_squared, root_mean_squared and peak_snr.
pub fn blit_rect(
&mut self,
src: impl AsArg<Option<Gd<Image>>>,
src_rect: Rect2i,
dst: Vector2i,
)
pub fn blit_rect( &mut self, src: impl AsArg<Option<Gd<Image>>>, src_rect: Rect2i, dst: Vector2i, )
Copies src_rect from src image to this image at coordinates dst, clipped accordingly to both image bounds. This image and src image must have the same format. src_rect with non-positive size is treated as empty.
Note: The alpha channel data in src will overwrite the corresponding data in this image at the target position. To blend alpha channels, use blend_rect instead.
pub fn blit_rect_mask(
&mut self,
src: impl AsArg<Option<Gd<Image>>>,
mask: impl AsArg<Option<Gd<Image>>>,
src_rect: Rect2i,
dst: Vector2i,
)
pub fn blit_rect_mask( &mut self, src: impl AsArg<Option<Gd<Image>>>, mask: impl AsArg<Option<Gd<Image>>>, src_rect: Rect2i, dst: Vector2i, )
Blits src_rect area from src image to this image at the coordinates given by dst, clipped accordingly to both image bounds. src pixel is copied onto dst if the corresponding mask pixel’s alpha value is not 0. This image and src image must have the same format. src image and mask image must have the same size (width and height) but they can have different formats. src_rect with non-positive size is treated as empty.
pub fn blend_rect(
&mut self,
src: impl AsArg<Option<Gd<Image>>>,
src_rect: Rect2i,
dst: Vector2i,
)
pub fn blend_rect( &mut self, src: impl AsArg<Option<Gd<Image>>>, src_rect: Rect2i, dst: Vector2i, )
Alpha-blends src_rect from src image to this image at coordinates dst, clipped accordingly to both image bounds. This image and src image must have the same format. src_rect with non-positive size is treated as empty.
pub fn blend_rect_mask(
&mut self,
src: impl AsArg<Option<Gd<Image>>>,
mask: impl AsArg<Option<Gd<Image>>>,
src_rect: Rect2i,
dst: Vector2i,
)
pub fn blend_rect_mask( &mut self, src: impl AsArg<Option<Gd<Image>>>, mask: impl AsArg<Option<Gd<Image>>>, src_rect: Rect2i, dst: Vector2i, )
Alpha-blends src_rect from src image to this image using mask image at coordinates dst, clipped accordingly to both image bounds. Alpha channels are required for both src and mask. dst pixels and src pixels will blend if the corresponding mask pixel’s alpha value is not 0. This image and src image must have the same format. src image and mask image must have the same size (width and height) but they can have different formats. src_rect with non-positive size is treated as empty.
pub fn get_used_rect(&self) -> Rect2i
pub fn get_used_rect(&self) -> Rect2i
Returns a Rect2i enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.
pub fn get_region(&self, region: Rect2i) -> Option<Gd<Image>>
pub fn get_region(&self, region: Rect2i) -> Option<Gd<Image>>
Returns a new Image that is a copy of this Image’s area specified with region.
pub fn get_pixelv(&self, point: Vector2i) -> Color
pub fn get_pixelv(&self, point: Vector2i) -> Color
pub fn get_pixel(&self, x: i32, y: i32) -> Color
pub fn get_pixel(&self, x: i32, y: i32) -> Color
Returns the color of the pixel at (x, y).
This is the same as get_pixelv, but with two integer arguments instead of a Vector2i argument.
pub fn set_pixelv(&mut self, point: Vector2i, color: Color)
pub fn set_pixelv(&mut self, point: Vector2i, color: Color)
Sets the Color of the pixel at point to color.
var img_width = 10
var img_height = 5
var img = Image.create(img_width, img_height, false, Image.FORMAT_RGBA8)
img.set_pixelv(Vector2i(1, 2), Color.RED) # Sets the color at (1, 2) to red.This is the same as set_pixel, but with a Vector2i argument instead of two integer arguments.
Note: Depending on the image’s format, the color set here may be clamped or lose precision. Do not assume the color returned by get_pixelv to be identical to the one set here; any comparisons will likely need to use an approximation like approx_eq.
Note: On grayscale image formats, only the red channel of color is used (and alpha if relevant). The green and blue channels are ignored.
pub fn set_pixel(&mut self, x: i32, y: i32, color: Color)
pub fn set_pixel(&mut self, x: i32, y: i32, color: Color)
Sets the Color of the pixel at (x, y) to color.
var img_width = 10
var img_height = 5
var img = Image.create(img_width, img_height, false, Image.FORMAT_RGBA8)
img.set_pixel(1, 2, Color.RED) # Sets the color at (1, 2) to red.This is the same as set_pixelv, but with a two integer arguments instead of a Vector2i argument.
Note: Depending on the image’s format, the color set here may be clamped or lose precision. Do not assume the color returned by get_pixel to be identical to the one set here; any comparisons will likely need to use an approximation like approx_eq.
Note: On grayscale image formats, only the red channel of color is used (and alpha if relevant). The green and blue channels are ignored.
pub fn adjust_bcs(&mut self, brightness: f32, contrast: f32, saturation: f32)
pub fn adjust_bcs(&mut self, brightness: f32, contrast: f32, saturation: f32)
Adjusts this image’s brightness, contrast, and saturation by the given values. Does not work if the image is compressed (see is_compressed).
pub fn load_png_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
pub fn load_png_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
Loads an image from the binary contents of a PNG file.
pub fn load_jpg_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
pub fn load_jpg_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
Loads an image from the binary contents of a JPEG file.
pub fn load_webp_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
pub fn load_webp_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
Loads an image from the binary contents of a WebP file.
pub fn load_tga_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
pub fn load_tga_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
Loads an image from the binary contents of a TGA file.
Note: This method is only available in engine builds with the TGA module enabled. By default, the TGA module is enabled, but it can be disabled at build-time using the module_tga_enabled=no SCons option.
pub fn load_bmp_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
pub fn load_bmp_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
Loads an image from the binary contents of a BMP file.
Note: Godot’s BMP module doesn’t support 16-bit per pixel images. Only 1-bit, 4-bit, 8-bit, 24-bit, and 32-bit per pixel images are supported.
Note: This method is only available in engine builds with the BMP module enabled. By default, the BMP module is enabled, but it can be disabled at build-time using the module_bmp_enabled=no SCons option.
pub fn load_ktx_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
pub fn load_ktx_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
Loads an image from the binary contents of a KTX file. Unlike most image formats, KTX can store VRAM-compressed data and embed mipmaps.
Note: Godot’s libktx implementation only supports 2D images. Cubemaps, texture arrays, and de-padding are not supported.
Note: This method is only available in engine builds with the KTX module enabled. By default, the KTX module is enabled, but it can be disabled at build-time using the module_ktx_enabled=no SCons option.
pub fn load_dds_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
pub fn load_dds_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
Loads an image from the binary contents of a DDS file.
Note: This method is only available in engine builds with the DDS module enabled. By default, the DDS module is enabled, but it can be disabled at build-time using the module_dds_enabled=no SCons option.
pub fn load_exr_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
pub fn load_exr_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
Loads an image from the binary contents of an OpenEXR file.
pub fn load_svg_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
pub fn load_svg_from_buffer(&mut self, buffer: &PackedArray<u8>) -> Error
To set the default parameters, use load_svg_from_buffer_ex and its builder methods. See the book for detailed usage instructions.
Loads an image from the UTF-8 binary contents of an uncompressed SVG file (.svg).
Note: Beware when using compressed SVG files (like .svgz), they need to be decompressed before loading.
Note: This method is only available in engine builds with the SVG module enabled. By default, the SVG module is enabled, but it can be disabled at build-time using the module_svg_enabled=no SCons option.
pub fn load_svg_from_buffer_ex<'ex>(
&'ex mut self,
buffer: &'ex PackedArray<u8>,
) -> ExLoadSvgFromBuffer<'ex>
pub fn load_svg_from_buffer_ex<'ex>( &'ex mut self, buffer: &'ex PackedArray<u8>, ) -> ExLoadSvgFromBuffer<'ex>
Loads an image from the UTF-8 binary contents of an uncompressed SVG file (.svg).
Note: Beware when using compressed SVG files (like .svgz), they need to be decompressed before loading.
Note: This method is only available in engine builds with the SVG module enabled. By default, the SVG module is enabled, but it can be disabled at build-time using the module_svg_enabled=no SCons option.
pub fn load_svg_from_string(&mut self, svg_str: impl AsArg<GString>) -> Error
pub fn load_svg_from_string(&mut self, svg_str: impl AsArg<GString>) -> Error
To set the default parameters, use load_svg_from_string_ex and its builder methods. See the book for detailed usage instructions.
Loads an image from the string contents of an SVG file (.svg).
Note: This method is only available in engine builds with the SVG module enabled. By default, the SVG module is enabled, but it can be disabled at build-time using the module_svg_enabled=no SCons option.
pub fn load_svg_from_string_ex<'ex>(
&'ex mut self,
svg_str: impl AsArg<GString> + 'ex,
) -> ExLoadSvgFromString<'ex>
pub fn load_svg_from_string_ex<'ex>( &'ex mut self, svg_str: impl AsArg<GString> + 'ex, ) -> ExLoadSvgFromString<'ex>
Loads an image from the string contents of an SVG file (.svg).
Note: This method is only available in engine builds with the SVG module enabled. By default, the SVG module is enabled, but it can be disabled at build-time using the module_svg_enabled=no SCons option.
Methods from Deref<Target = Resource>§
pub fn set_path(&mut self, path: impl AsArg<GString>)
pub fn take_over_path(&mut self, path: impl AsArg<GString>)
pub fn take_over_path(&mut self, path: impl AsArg<GString>)
Sets the [member resource_path] to path, potentially overriding an existing cache entry for this path. Further attempts to load an overridden resource by path will instead return this resource.
pub fn get_path(&self) -> GString
pub fn set_path_cache(&mut self, path: impl AsArg<GString>)
pub fn set_path_cache(&mut self, path: impl AsArg<GString>)
Sets the resource’s path to path without involving the resource cache. Useful for handling [enum ResourceFormatLoader.CacheMode] values when implementing a custom resource format by extending ResourceFormatLoader and ResourceFormatSaver.
pub fn set_name(&mut self, name: impl AsArg<GString>)
pub fn get_name(&self) -> GString
pub fn get_rid(&self) -> Rid
pub fn get_rid(&self) -> Rid
Returns the RID of this resource (or an empty RID). Many resources (such as Texture2D, Mesh, and so on) are high-level abstractions of resources stored in a specialized server (DisplayServer, RenderingServer, etc.), so this function will return the original RID.
pub fn set_local_to_scene(&mut self, enable: bool)
pub fn is_local_to_scene(&self) -> bool
pub fn get_local_scene(&self) -> Option<Gd<Node>>
pub fn get_local_scene(&self) -> Option<Gd<Node>>
If [member resource_local_to_scene] is set to true and the resource has been loaded from a PackedScene instantiation, returns the root Node of the scene where this resource is used. Otherwise, returns null.
pub fn setup_local_to_scene(&mut self)
pub fn setup_local_to_scene(&mut self)
Calls setup_local_to_scene. If [member resource_local_to_scene] is set to true, this method is automatically called from instantiate by the newly duplicated resource within the scene instance.
pub fn reset_state(&mut self)
pub fn reset_state(&mut self)
Makes the resource clear its non-exported properties. See also reset_state. Useful when implementing a custom resource format by extending ResourceFormatLoader and ResourceFormatSaver.
pub fn set_id_for_path(
&mut self,
path: impl AsArg<GString>,
id: impl AsArg<GString>,
)
pub fn set_id_for_path( &mut self, path: impl AsArg<GString>, id: impl AsArg<GString>, )
In the internal cache for scene-unique IDs, sets the ID of this resource to id for the scene at path. If id is empty, the cache entry for path is cleared. Useful to keep scene-unique IDs the same when implementing a VCS-friendly custom resource format by extending ResourceFormatLoader and ResourceFormatSaver.
Note: This method is only implemented when running in an editor context.
pub fn get_id_for_path(&self, path: impl AsArg<GString>) -> GString
pub fn get_id_for_path(&self, path: impl AsArg<GString>) -> GString
From the internal cache for scene-unique IDs, returns the ID of this resource for the scene at path. If there is no entry, an empty string is returned. Useful to keep scene-unique IDs the same when implementing a VCS-friendly custom resource format by extending ResourceFormatLoader and ResourceFormatSaver.
Note: This method is only implemented when running in an editor context. At runtime, it returns an empty string.
pub fn is_built_in(&self) -> bool
pub fn is_built_in(&self) -> bool
Returns true if the resource is saved on disk as a part of another resource’s file.
pub fn set_scene_unique_id(&mut self, id: impl AsArg<GString>)
pub fn get_scene_unique_id(&self) -> GString
pub fn emit_changed(&mut self)
pub fn emit_changed(&mut self)
Emits the changed signal. This method is called automatically for some built-in resources.
Note: For custom resources, it’s recommended to call this method whenever a meaningful change occurs, such as a modified property. This ensures that custom Objects depending on the resource are properly updated.
var damage:
set(new_value):
if damage != new_value:
damage = new_value
emit_changed()pub fn duplicate(&self) -> Option<Gd<Resource>>
👎Deprecated: Use Gd::duplicate_resource() or Gd::duplicate_resource_ex().
pub fn duplicate(&self) -> Option<Gd<Resource>>
Use Gd::duplicate_resource() or Gd::duplicate_resource_ex().
To set the default parameters, use duplicate_ex and its builder methods. See the book for detailed usage instructions.
Duplicates this resource, returning a new resource with its exported or PropertyUsageFlags::STORAGE properties copied from the original.
If deep is false, a shallow copy is returned: nested Array, Dictionary, and Resource properties are not duplicated and are shared with the original resource.
If deep is true, a deep copy is returned: all nested arrays, dictionaries, and packed arrays are also duplicated (recursively). Any Resource found inside will only be duplicated if it’s local, like DeepDuplicateMode::INTERNAL used with duplicate_deep.
The following exceptions apply:
-
Subresource properties with the
PropertyUsageFlags::ALWAYS_DUPLICATEflag are always duplicated (recursively or not, depending ondeep). -
Subresource properties with the
PropertyUsageFlags::NEVER_DUPLICATEflag are never duplicated.
Note: For custom resources, this method will fail if init has been defined with required parameters.
Note: When duplicating with deep set to true, each resource found, including the one on which this method is called, will be only duplicated once and referenced as many times as needed in the duplicate. For instance, if you are duplicating resource A that happens to have resource B referenced twice, you’ll get a new resource A’ referencing a new resource B’ twice.
pub fn duplicate_ex<'ex>(&'ex self) -> ExDuplicate<'ex>
👎Deprecated: Use Gd::duplicate_resource() or Gd::duplicate_resource_ex().
pub fn duplicate_ex<'ex>(&'ex self) -> ExDuplicate<'ex>
Use Gd::duplicate_resource() or Gd::duplicate_resource_ex().
Duplicates this resource, returning a new resource with its exported or PropertyUsageFlags::STORAGE properties copied from the original.
If deep is false, a shallow copy is returned: nested Array, Dictionary, and Resource properties are not duplicated and are shared with the original resource.
If deep is true, a deep copy is returned: all nested arrays, dictionaries, and packed arrays are also duplicated (recursively). Any Resource found inside will only be duplicated if it’s local, like DeepDuplicateMode::INTERNAL used with duplicate_deep.
The following exceptions apply:
-
Subresource properties with the
PropertyUsageFlags::ALWAYS_DUPLICATEflag are always duplicated (recursively or not, depending ondeep). -
Subresource properties with the
PropertyUsageFlags::NEVER_DUPLICATEflag are never duplicated.
Note: For custom resources, this method will fail if init has been defined with required parameters.
Note: When duplicating with deep set to true, each resource found, including the one on which this method is called, will be only duplicated once and referenced as many times as needed in the duplicate. For instance, if you are duplicating resource A that happens to have resource B referenced twice, you’ll get a new resource A’ referencing a new resource B’ twice.
pub fn duplicate_deep(&self) -> Option<Gd<Resource>>
👎Deprecated: Use Gd::duplicate_resource() or Gd::duplicate_resource_ex().
pub fn duplicate_deep(&self) -> Option<Gd<Resource>>
Use Gd::duplicate_resource() or Gd::duplicate_resource_ex().
To set the default parameters, use duplicate_deep_ex and its builder methods. See the book for detailed usage instructions.
Duplicates this resource, deeply, like duplicate when passing true, with extra control over how subresources are handled.
pub fn duplicate_deep_ex<'ex>(&'ex self) -> ExDuplicateDeep<'ex>
👎Deprecated: Use Gd::duplicate_resource() or Gd::duplicate_resource_ex().
pub fn duplicate_deep_ex<'ex>(&'ex self) -> ExDuplicateDeep<'ex>
Use Gd::duplicate_resource() or Gd::duplicate_resource_ex().
Duplicates this resource, deeply, like duplicate when passing true, with extra control over how subresources are handled.
Methods from Deref<Target = RefCounted>§
pub fn get_reference_count(&self) -> i32
pub fn get_reference_count(&self) -> i32
Returns the current reference count.
Methods from Deref<Target = Object>§
pub fn get_script(&self) -> Option<Gd<Script>>
pub fn set_script(&mut self, script: impl AsArg<Option<Gd<Script>>>)
pub fn connect( &mut self, signal: impl AsArg<StringName>, callable: &Callable, ) -> Error
pub fn connect_flags( &mut self, signal: impl AsArg<StringName>, callable: &Callable, flags: ConnectFlags, ) -> Error
pub fn is_class(&self, class: impl AsArg<GString>) -> bool
pub fn is_class(&self, class: impl AsArg<GString>) -> bool
Returns true if the object inherits from the given class. See also get_class.
var sprite2d = Sprite2D.new()
sprite2d.is_class("Sprite2D") # Returns true
sprite2d.is_class("Node") # Returns true
sprite2d.is_class("Node3D") # Returns falseNote: This method ignores class_name declarations in the object’s script.
pub fn set(&mut self, property: impl AsArg<StringName>, value: &Variant)
pub fn set(&mut self, property: impl AsArg<StringName>, value: &Variant)
Assigns value to the given property. If the property does not exist or the given value’s type doesn’t match, nothing happens.
var node = Node2D.new()
node.set("global_scale", Vector2(8, 2.5))
print(node.global_scale) # Prints (8.0, 2.5)Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
pub fn get(&self, property: impl AsArg<StringName>) -> Variant
pub fn get(&self, property: impl AsArg<StringName>) -> Variant
Returns the Variant value of the given property. If the property does not exist, this method returns null.
var node = Node2D.new()
node.rotation = 1.5
var a = node.get("rotation") # a is 1.5Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
pub fn set_indexed(
&mut self,
property_path: impl AsArg<NodePath>,
value: &Variant,
)
pub fn set_indexed( &mut self, property_path: impl AsArg<NodePath>, value: &Variant, )
Assigns a new value to the property identified by the property_path. The path should be a NodePath relative to this object, and can use the colon character (:) to access nested properties.
var node = Node2D.new()
node.set_indexed("position", Vector2(42, 0))
node.set_indexed("position:y", -10)
print(node.position) # Prints (42.0, -10.0)Note: In C#, property_path must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
pub fn get_indexed(&self, property_path: impl AsArg<NodePath>) -> Variant
pub fn get_indexed(&self, property_path: impl AsArg<NodePath>) -> Variant
Gets the object’s property indexed by the given property_path. The path should be a NodePath relative to the current object and can use the colon character (:) to access nested properties.
Examples: "position:x" or "material:next_pass:blend_mode".
var node = Node2D.new()
node.position = Vector2(5, -10)
var a = node.get_indexed("position") # a is Vector2(5, -10)
var b = node.get_indexed("position:y") # b is -10Note: In C#, property_path must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
Note: This method does not support actual paths to nodes in the SceneTree, only sub-property paths. In the context of nodes, use get_node_and_resource instead.
pub fn get_property_list(&self) -> Array<Dictionary<Variant, Variant>>
pub fn get_property_list(&self) -> Array<Dictionary<Variant, Variant>>
Returns the object’s property list as an Array of dictionaries. Each Dictionary contains the following entries:
-
nameis the property’s name, as aString; -
class_nameis an emptyStringName, unless the property isVariantType::OBJECTand it inherits from a class; -
typeis the property’s type, as anint(see [enum Variant.Type]); -
hintis how the property is meant to be edited (see [enum PropertyHint]); -
hint_stringdepends on the hint (see [enum PropertyHint]); -
usageis a combination of [enum PropertyUsageFlags].
Note: In GDScript, all class members are treated as properties. In C# and GDExtension, it may be necessary to explicitly mark class members as Godot properties using decorators or attributes.
pub fn get_method_list(&self) -> Array<Dictionary<Variant, Variant>>
pub fn get_method_list(&self) -> Array<Dictionary<Variant, Variant>>
Returns this object’s methods and their signatures as an Array of dictionaries. Each Dictionary contains the following entries:
-
nameis the name of the method, as aString; -
argsis anArrayof dictionaries representing the arguments; -
default_argsis the default arguments as anArrayof variants; -
flagsis a combination of [enum MethodFlags]; -
idis the method’s internal identifierint; -
returnis the returned value, as aDictionary;
Note: The dictionaries of args and return are formatted identically to the results of get_property_list, although not all entries are used.
pub fn property_can_revert(&self, property: impl AsArg<StringName>) -> bool
pub fn property_can_revert(&self, property: impl AsArg<StringName>) -> bool
Returns true if the given property has a custom default value. Use property_get_revert to get the property’s default value.
Note: This method is used by the Inspector dock to display a revert icon. The object must implement [method _property_can_revert] to customize the default value. If [method _property_can_revert] is not implemented, this method returns false.
pub fn property_get_revert(&self, property: impl AsArg<StringName>) -> Variant
pub fn property_get_revert(&self, property: impl AsArg<StringName>) -> Variant
Returns the custom default value of the given property. Use property_can_revert to check if the property has a custom default value.
Note: This method is used by the Inspector dock to display a revert icon. The object must implement [method _property_get_revert] to customize the default value. If [method _property_get_revert] is not implemented, this method returns null.
pub fn set_meta(&mut self, name: impl AsArg<StringName>, value: &Variant)
pub fn set_meta(&mut self, name: impl AsArg<StringName>, value: &Variant)
Adds or changes the entry name inside the object’s metadata. The metadata value can be any Variant, although some types cannot be serialized correctly.
If value is null, the entry is removed. This is the equivalent of using remove_meta. See also has_meta and get_meta.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn remove_meta(&mut self, name: impl AsArg<StringName>)
pub fn remove_meta(&mut self, name: impl AsArg<StringName>)
Removes the given entry name from the object’s metadata. See also has_meta, get_meta and set_meta.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn get_meta(&self, name: impl AsArg<StringName>) -> Variant
pub fn get_meta(&self, name: impl AsArg<StringName>) -> Variant
To set the default parameters, use get_meta_ex and its builder methods. See the book for detailed usage instructions.
Returns the object’s metadata value for the given entry name. If the entry does not exist, returns default. If default is null, an error is also generated.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn get_meta_ex<'ex>(
&'ex self,
name: impl AsArg<StringName> + 'ex,
) -> ExGetMeta<'ex>
pub fn get_meta_ex<'ex>( &'ex self, name: impl AsArg<StringName> + 'ex, ) -> ExGetMeta<'ex>
Returns the object’s metadata value for the given entry name. If the entry does not exist, returns default. If default is null, an error is also generated.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn has_meta(&self, name: impl AsArg<StringName>) -> bool
pub fn has_meta(&self, name: impl AsArg<StringName>) -> bool
Returns true if a metadata entry is found with the given name. See also get_meta, set_meta and remove_meta.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn get_meta_list(&self) -> Array<StringName>
pub fn get_meta_list(&self) -> Array<StringName>
Returns the object’s metadata entry names as an Array of StringNames.
pub fn add_user_signal(&mut self, signal: impl AsArg<GString>)
pub fn add_user_signal(&mut self, signal: impl AsArg<GString>)
To set the default parameters, use add_user_signal_ex and its builder methods. See the book for detailed usage instructions.
Adds a user-defined signal named signal. Optional arguments for the signal can be added as an Array of dictionaries, each defining a name String and a type int (see [enum Variant.Type]). See also has_user_signal and remove_user_signal.
add_user_signal("hurt", [
{ "name": "damage", "type": TYPE_INT },
{ "name": "source", "type": TYPE_OBJECT }
])pub fn add_user_signal_ex<'ex>(
&'ex mut self,
signal: impl AsArg<GString> + 'ex,
) -> ExAddUserSignal<'ex>
pub fn add_user_signal_ex<'ex>( &'ex mut self, signal: impl AsArg<GString> + 'ex, ) -> ExAddUserSignal<'ex>
Adds a user-defined signal named signal. Optional arguments for the signal can be added as an Array of dictionaries, each defining a name String and a type int (see [enum Variant.Type]). See also has_user_signal and remove_user_signal.
add_user_signal("hurt", [
{ "name": "damage", "type": TYPE_INT },
{ "name": "source", "type": TYPE_OBJECT }
])pub fn has_user_signal(&self, signal: impl AsArg<StringName>) -> bool
pub fn has_user_signal(&self, signal: impl AsArg<StringName>) -> bool
Returns true if the given user-defined signal name exists. Only signals added with add_user_signal are included. See also remove_user_signal.
pub fn remove_user_signal(&mut self, signal: impl AsArg<StringName>)
pub fn remove_user_signal(&mut self, signal: impl AsArg<StringName>)
Removes the given user signal signal from the object. See also add_user_signal and has_user_signal.
pub fn emit_signal(
&mut self,
signal: impl AsArg<StringName>,
varargs: &[Variant],
) -> Error
pub fn emit_signal( &mut self, signal: impl AsArg<StringName>, varargs: &[Variant], ) -> Error
Emits the given signal by name. The signal must exist, so it should be a built-in signal of this class or one of its inherited classes, or a user-defined signal (see add_user_signal). This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
Returns Error::ERR_UNAVAILABLE if signal does not exist or the parameters are invalid.
emit_signal("hit", "sword", 100)
emit_signal("game_over")Note: In C#, signal must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.
§Panics
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will panic in such a case.
pub fn try_emit_signal(
&mut self,
signal: impl AsArg<StringName>,
varargs: &[Variant],
) -> Result<Error, CallError>
pub fn try_emit_signal( &mut self, signal: impl AsArg<StringName>, varargs: &[Variant], ) -> Result<Error, CallError>
§Return type
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will return Err in such a case.
pub fn call(
&mut self,
method: impl AsArg<StringName>,
varargs: &[Variant],
) -> Variant
pub fn call( &mut self, method: impl AsArg<StringName>, varargs: &[Variant], ) -> Variant
Calls the method on the object and returns the result. This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
var node = Node3D.new()
node.call("rotate", Vector3(1.0, 0.0, 0.0), 1.571)Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
§Panics
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will panic in such a case.
pub fn try_call(
&mut self,
method: impl AsArg<StringName>,
varargs: &[Variant],
) -> Result<Variant, CallError>
pub fn try_call( &mut self, method: impl AsArg<StringName>, varargs: &[Variant], ) -> Result<Variant, CallError>
§Return type
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will return Err in such a case.
pub fn call_deferred(
&mut self,
method: impl AsArg<StringName>,
varargs: &[Variant],
) -> Variant
pub fn call_deferred( &mut self, method: impl AsArg<StringName>, varargs: &[Variant], ) -> Variant
Calls the method on the object during idle time. Always returns null, not the method’s result.
Idle time happens mainly at the end of process and physics frames. In it, deferred calls will be run until there are none left, which means you can defer calls from other deferred calls and they’ll still be run in the current idle time cycle. This means you should not call a method deferred from itself (or from a method called by it), as this causes infinite recursion the same way as if you had called the method directly.
This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
var node = Node3D.new()
node.call_deferred("rotate", Vector3(1.0, 0.0, 0.0), 1.571)For methods that are deferred from the same thread, the order of execution at idle time is identical to the order in which call_deferred was called.
See also call_deferred.
Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
Note: If you’re looking to delay the function call by a frame, refer to the SceneTree.process_frame and SceneTree.physics_frame signals.
var node = Node3D.new()
# Make a Callable and bind the arguments to the node's rotate() call.
var callable = node.rotate.bind(Vector3(1.0, 0.0, 0.0), 1.571)
# Connect the callable to the process_frame signal, so it gets called in the next process frame.
# CONNECT_ONE_SHOT makes sure it only gets called once instead of every frame.
get_tree().process_frame.connect(callable, CONNECT_ONE_SHOT)§Panics
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will panic in such a case.
pub fn try_call_deferred(
&mut self,
method: impl AsArg<StringName>,
varargs: &[Variant],
) -> Result<Variant, CallError>
pub fn try_call_deferred( &mut self, method: impl AsArg<StringName>, varargs: &[Variant], ) -> Result<Variant, CallError>
§Return type
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will return Err in such a case.
pub fn set_deferred(
&mut self,
property: impl AsArg<StringName>,
value: &Variant,
)
pub fn set_deferred( &mut self, property: impl AsArg<StringName>, value: &Variant, )
Assigns value to the given property, at the end of the current frame. This is equivalent to calling set through call_deferred.
var node = Node2D.new()
add_child(node)
node.rotation = 1.5
node.set_deferred("rotation", 3.0)
print(node.rotation) # Prints 1.5
await get_tree().process_frame
print(node.rotation) # Prints 3.0Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
pub fn callv(
&mut self,
method: impl AsArg<StringName>,
arg_array: &AnyArray,
) -> Variant
pub fn callv( &mut self, method: impl AsArg<StringName>, arg_array: &AnyArray, ) -> Variant
Calls the method on the object and returns the result. Unlike call, this method expects all parameters to be contained inside arg_array.
var node = Node3D.new()
node.callv("rotate", [Vector3(1.0, 0.0, 0.0), 1.571])Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
pub fn has_method(&self, method: impl AsArg<StringName>) -> bool
pub fn has_method(&self, method: impl AsArg<StringName>) -> bool
Returns true if the given method name exists in the object.
Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
pub fn get_method_argument_count(&self, method: impl AsArg<StringName>) -> i32
pub fn get_method_argument_count(&self, method: impl AsArg<StringName>) -> i32
Returns the number of arguments of the given method by name.
Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
pub fn has_signal(&self, signal: impl AsArg<StringName>) -> bool
pub fn has_signal(&self, signal: impl AsArg<StringName>) -> bool
Returns true if the given signal name exists in the object.
Note: In C#, signal must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.
pub fn get_signal_list(&self) -> Array<Dictionary<Variant, Variant>>
pub fn get_signal_list(&self) -> Array<Dictionary<Variant, Variant>>
Returns the list of existing signals as an Array of dictionaries.
Note: Due to the implementation, each Dictionary is formatted very similarly to the returned values of get_method_list.
pub fn get_signal_connection_list(
&self,
signal: impl AsArg<StringName>,
) -> Array<Dictionary<Variant, Variant>>
pub fn get_signal_connection_list( &self, signal: impl AsArg<StringName>, ) -> Array<Dictionary<Variant, Variant>>
Returns an Array of connections for the given signal name. Each connection is represented as a Dictionary that contains three entries:
pub fn get_incoming_connections(&self) -> Array<Dictionary<Variant, Variant>>
pub fn get_incoming_connections(&self) -> Array<Dictionary<Variant, Variant>>
Returns an Array of signal connections received by this object. Each connection is represented as a Dictionary that contains three entries:
pub fn disconnect(
&mut self,
signal: impl AsArg<StringName>,
callable: &Callable,
)
pub fn disconnect( &mut self, signal: impl AsArg<StringName>, callable: &Callable, )
Disconnects a signal by name from a given callable. If the connection does not exist, generates an error. Use is_connected to make sure that the connection exists.
pub fn is_connected(
&self,
signal: impl AsArg<StringName>,
callable: &Callable,
) -> bool
pub fn is_connected( &self, signal: impl AsArg<StringName>, callable: &Callable, ) -> bool
Returns true if a connection exists between the given signal name and callable.
Note: In C#, signal must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.
pub fn has_connections(&self, signal: impl AsArg<StringName>) -> bool
pub fn has_connections(&self, signal: impl AsArg<StringName>) -> bool
Returns true if any connection exists on the given signal name.
Note: In C#, signal must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.
pub fn set_block_signals(&mut self, enable: bool)
pub fn set_block_signals(&mut self, enable: bool)
If set to true, the object becomes unable to emit signals. As such, emit_signal and signal connections will not work, until it is set to false.
pub fn is_blocking_signals(&self) -> bool
pub fn is_blocking_signals(&self) -> bool
Returns true if the object is blocking its signals from being emitted. See set_block_signals.
pub fn notify_property_list_changed(&mut self)
pub fn notify_property_list_changed(&mut self)
Emits the property_list_changed signal. This is mainly used to refresh the editor, so that the Inspector and editor plugins are properly updated.
pub fn set_message_translation(&mut self, enable: bool)
pub fn set_message_translation(&mut self, enable: bool)
If set to true, allows the object to translate messages with tr and tr_n. Enabled by default. See also can_translate_messages.
pub fn can_translate_messages(&self) -> bool
pub fn can_translate_messages(&self) -> bool
Returns true if the object is allowed to translate messages with tr and tr_n. See also set_message_translation.
pub fn tr(&self, message: impl AsArg<StringName>) -> GString
pub fn tr(&self, message: impl AsArg<StringName>) -> GString
To set the default parameters, use tr_ex and its builder methods. See the book for detailed usage instructions.
Translates a message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation. Note that most Control nodes automatically translate their strings, so this method is mostly useful for formatted strings or custom drawn text.
If can_translate_messages is false, or no translation is available, this method returns the message without changes. See set_message_translation.
For detailed examples, see Internationalizing games.
Note: This method can’t be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use translate.
pub fn tr_ex<'ex>(&'ex self, message: impl AsArg<StringName> + 'ex) -> ExTr<'ex>
pub fn tr_ex<'ex>(&'ex self, message: impl AsArg<StringName> + 'ex) -> ExTr<'ex>
Translates a message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation. Note that most Control nodes automatically translate their strings, so this method is mostly useful for formatted strings or custom drawn text.
If can_translate_messages is false, or no translation is available, this method returns the message without changes. See set_message_translation.
For detailed examples, see Internationalizing games.
Note: This method can’t be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use translate.
pub fn tr_n(
&self,
message: impl AsArg<StringName>,
plural_message: impl AsArg<StringName>,
n: i32,
) -> GString
pub fn tr_n( &self, message: impl AsArg<StringName>, plural_message: impl AsArg<StringName>, n: i32, ) -> GString
To set the default parameters, use tr_n_ex and its builder methods. See the book for detailed usage instructions.
Translates a message or plural_message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation.
If can_translate_messages is false, or no translation is available, this method returns message or plural_message, without changes. See set_message_translation.
The n is the number, or amount, of the message’s subject. It is used by the translation system to fetch the correct plural form for the current language.
For detailed examples, see Localization using gettext.
Note: Negative and float numbers may not properly apply to some countable subjects. It’s recommended to handle these cases with tr.
Note: This method can’t be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use translate_plural.
pub fn tr_n_ex<'ex>(
&'ex self,
message: impl AsArg<StringName> + 'ex,
plural_message: impl AsArg<StringName> + 'ex,
n: i32,
) -> ExTrN<'ex>
pub fn tr_n_ex<'ex>( &'ex self, message: impl AsArg<StringName> + 'ex, plural_message: impl AsArg<StringName> + 'ex, n: i32, ) -> ExTrN<'ex>
Translates a message or plural_message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation.
If can_translate_messages is false, or no translation is available, this method returns message or plural_message, without changes. See set_message_translation.
The n is the number, or amount, of the message’s subject. It is used by the translation system to fetch the correct plural form for the current language.
For detailed examples, see Localization using gettext.
Note: Negative and float numbers may not properly apply to some countable subjects. It’s recommended to handle these cases with tr.
Note: This method can’t be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use translate_plural.
pub fn get_translation_domain(&self) -> StringName
pub fn get_translation_domain(&self) -> StringName
Returns the name of the translation domain used by tr and tr_n. See also TranslationServer.
pub fn set_translation_domain(&mut self, domain: impl AsArg<StringName>)
pub fn set_translation_domain(&mut self, domain: impl AsArg<StringName>)
Sets the name of the translation domain used by tr and tr_n. See also TranslationServer.
pub fn is_queued_for_deletion(&self) -> bool
pub fn is_queued_for_deletion(&self) -> bool
Returns true if the queue_free method was called for the object.
pub fn cancel_free(&mut self)
pub fn cancel_free(&mut self)
If this method is called during ObjectNotification::PREDELETE, this object will reject being freed and will remain allocated. This is mostly an internal function used for error handling to avoid the user from freeing objects when they are not intended to.
pub fn notify(&mut self, what: ObjectNotification)
pub fn notify(&mut self, what: ObjectNotification)
⚠️ Sends a Godot notification to all classes inherited by the object.
Triggers calls to on_notification(), and depending on the notification, also to Godot’s lifecycle callbacks such as ready().
Starts from the highest ancestor (the Object class) and goes down the hierarchy.
See also Godot docs for Object::notification().
§Panics
If you call this method on a user-defined object while holding a GdRef or GdMut guard on the instance, you will encounter
a panic. The reason is that the receiving virtual method on_notification() acquires a GdMut lock dynamically, which must
be exclusive.
pub fn notify_reversed(&mut self, what: ObjectNotification)
pub fn notify_reversed(&mut self, what: ObjectNotification)
⚠️ Like Self::notify(), but starts at the most-derived class and goes up the hierarchy.
See docs of that method, including the panics.
Trait Implementations§
§impl Bounds for Image
impl Bounds for Image
§type Memory = MemRefCounted
type Memory = MemRefCounted
§type Declarer = DeclEngine
type Declarer = DeclEngine
§impl GodotClass for Image
impl GodotClass for Image
§const INIT_LEVEL: InitLevel = crate::init::InitLevel::Scene
const INIT_LEVEL: InitLevel = crate::init::InitLevel::Scene
§fn class_id() -> ClassId
fn class_id() -> ClassId
§fn inherits<Base>() -> boolwhere
Base: GodotClass,
fn inherits<Base>() -> boolwhere
Base: GodotClass,
§impl Inherits<RefCounted> for Image
impl Inherits<RefCounted> for Image
§const IS_SAME_CLASS: bool = false
const IS_SAME_CLASS: bool = false
Self == Base. Read more§impl Inherits<Resource> for Image
impl Inherits<Resource> for Image
§const IS_SAME_CLASS: bool = false
const IS_SAME_CLASS: bool = false
Self == Base. Read more§impl WithSignals for Image
impl WithSignals for Image
§type SignalCollection<'c, C: WithSignals> = SignalsOfResource<'c, C>
type SignalCollection<'c, C: WithSignals> = SignalsOfResource<'c, C>
impl GodotDefault for Image
Auto Trait Implementations§
impl Freeze for Image
impl RefUnwindSafe for Image
impl !Send for Image
impl !Sync for Image
impl Unpin for Image
impl UnsafeUnpin for Image
impl UnwindSafe for Image
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Inherits<T> for Twhere
T: GodotClass,
impl<T> Inherits<T> for Twhere
T: GodotClass,
§const IS_SAME_CLASS: bool = true
const IS_SAME_CLASS: bool = true
Self == Base. Read more