problem getting a portion of an image

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Matty101

What i’m trying to accomplish is for the mouse cursor to change to the sprites image when i click that sprite.

what i have so far is:

func on_click():
	var dragable_Image = get_node("../Icon_image")  
	var Image_rect = dragable_Image.get_region_rect()
	var new_Icon = dragable_Image.get_texture().get_data().get_rect(Image_rect)

comes up with: Condition ’ !texture.is_valid() ’ is true.

so i’m guessing i’m miss-handling some data on that 2nd last line and new_icon isn’t getting texture data

Which line did cause the error? (you should be able to check in the bottom panel of the editor)

Zylann | 2020-03-25 23:44

the custom mouse cursor is the line with error

Matty101 | 2020-03-26 00:10

:bust_in_silhouette: Reply From: Zylann

set_custom_mouse_cursor expects a Texture, not an Image. new_Icon is an image here.

It’s a confusing API, as the argument type is not specific and it says “image” while not handling images properly. Worse, because of this, you got an Image from a Texture, which you will have to re-upload to the graphics card by creating a Texture, for the function to download it again just to get an image and create a bitmap internally for the OS… surreal, isn’t it ^^"
It looks like a bug.

Following the code on Windows:

Assuming you are hitting this

Accepting images would be possible with a few changes, but maybe there was an implementation mistake in the first place?

yup your right, i used create_from_image() function to convert it and got it working.

thx for your help

Matty101 | 2020-03-26 00:28