Getting size of a sprite from Gameobject (DEF-2407)

So in my current game I want to use a lot of temp art to be replaced later and I dont know the actual size the final art will be. So to code my game in a way that it wont break whenever I do this I would like to be able to get the size of the sprite used for the game object but I can’t for the life of me find any way to do so.

Is there a way to get information about this type of thing from game objects? I looked at the api for them (http://www.defold.com/ref/go/) but couldnt find anything other than scale of the object.

Sprites have a size property. See http://www.defold.com/manuals/properties/

Use go.get() to read properties. See http://www.defold.com/ref/go/#go.get:url-id

1 Like

So I was playing with this property, and one of the issues I am finding is that when I dynamically update the sprite’s image from the atlas using playanimation if that atlas item is different in size from the runtime set sprite model the go.get size request returns the runtime size of the image loaded to the sprite not the current image size. Is there something I’m missing or doing wrong?

Actually, this seems to happen in my init code, and when I use the function(update) to see if it realizes it later it does. So it seems to be a timing issue of when you check the sprite size.

In my example where it’s coming out wrong, I do set the sprite image different before issuing the check on sprite size later in my init function, but for some reason it doesn’t seem to like the timing of it.

Will be experimenting with some way to know that the image has changed and it’s ok to check for the updated sprite size… suggestions welcomed.

Since msg.post() is asynchronous the actual message processing will happen after the init() function. The solution is to wait for the animation_done message and at that point read the sprite size.

BUT, me and Ben came to the conclusion after some discussion on Slack that you do not get an animation_done message back when you do play_animation on a single image that isn’t in an animation group. This is a bug, reported as DEF-2407.

2 Likes

Did this bug DEF-2407 ever get solved?

1 Like

No, afraid not. It hasn’t been brought up since we discussed it last time.

Well glad I asked :wink:

2 Likes