Reading a Sprite Material Constant

I have a game object containing a sprite node, whose tint I change on creation (via a factory) like this:

sprite.set_constant(’#sprite’, ‘tint’, myVec4)

but for the life of me, I can’t figure out how to read this value at a later time.

Can someone assist me in that capacity?

Could you store the tint somewhere in self and then use it later? Or probably you already have it there if you passed the tint as a property at factory creation time?

But probably I am missing something…

My guess was that you could use:

-- recommended instead of sprite.set_constant() as it is a deprecated function
go.set("#sprite", "tint", vmath.vector4(1,1,0,1))

-- read it next frame
print(go.get("#sprite", "tint"))

But for some reason go.get() will give me the original value. I don’t recall why that is. @JCash probably knows!

If I spawn a sprite from factory, use go.set(sprite, “tint”, col)
and destroy it each frame, the memory used by defold keeps increasing. It only happens with tint, so I think that may be related to getting the unexpected value back.

If you do it enough you can see it’s a memory leak still. I made an issue on github for it.

2 Likes