How to get Sprite from the GO from the file? (SOLVED)

Yes you can. It is a read only property:

2 Likes

Yeah, but how to get the GO that in the sceen and after that get sprite property, i can’t understand code. Please give example.

Weird I thought otherwise… :man_shrugging:

Here you go: https://www.defold.com/examples/sprite/size/

Oh, thank you so much, i will check it when back home

The only problem is, your code is in “main.script”, which is not the script on the card object, so you can’t use the relative URL like that ("#card-tile"). If you only give the component ID, then it will look for it on the current object. You need to use a URL that is relative to where “main.script” is, or an absolute URL.

yeah, can you give an example of absolute url?

Open your card script, and in the init function, put:

print(msg.url())

Then, when you run your game, you will see the absolute URLs of all your cards, in the console. (The part inside the square brackets.)

oh, thanks. I forgot about it .

You can also see an example of this in the Sprite Size example I created:

local square_size = go.get("square#stone", "size")

“Read the size of the sprite with id stone on the game object with id square .”

yeah, they already helped me)