How to animate GO alpha Property? (SOLVED)

There is a way to animate the alpha(color) in a GO or only to GUI?

go.property("color", vmath.vector4(0, 0, 0, 0))
...

local function anim_born(self)
	
	
	pprint(self.color)
	go.animate(go.get_id(), hash("color"), go.PLAYBACK_ONCE_FORWARD, vmath.vector4(0,0,0,1), go.EASING_INBOUNCE, 0, 0)
	pprint(self.color)
end


error:

DEBUG:SCRIPT: vmath.vector4(0, 0, 0, 0)
ERROR:SCRIPT: dino/dino.script:28: '[main:/instance2]' does not have any property called 'color'
stack traceback:
	[C]: in function 'animate'
	dino/dino.script:28: in function 'anim_born'
	dino/dino.script:35: in function <dino/dino.script:34>
	[C]: in function 'create'
	dino/dino_factory.script:9: in function 'create'
	dino/dino_factory.script:15: in function <dino/dino_factory.script:13>
ERROR:GAMEOBJECT: Could not initialize when spawning /dino/dino.goc.
ERROR:GAMEOBJECT: Could not spawn an instance of prototype /dino/dino.goc.

is it this the same erro: Go.animate('#sprite','tint',...) bug (DEF-2095) ?

or I’m doing something wrong?

There is no “color” property on game objects. You can animate "tint"on sprites, tilemaps, spine etc though.

2 Likes

You want

sprite.set_constant("#sprite", "tint", vmath.vector4(1, 1, 1, .5))

the .5 on the end will change the sprite to 50% alpha

6 Likes

(this is because GO’s sprites already have a colour, and all you can do is “tint” the colour that it already has! You draw a GUI element yourself, so you have to provide the “colour” rather than just tinting it).

2 Likes

Work!!! thankyou guys

1 Like

Two alternative solutions:

go.set("#sprite", "tint", vmath.vector4(1, 1, 1, .5))
go.animate("#sprite", "tint", go.PLAYBACK_ONCE_FORWARD, vmath.vector4(1, 1, 1, .5), go.EASING_LINEAR, 1)

The go.animate() obviously fade the alpha to 50% instead of directly changing it. Note also that you can set/animate the individual values as well, for instance “tint.w” for alpha.

7 Likes