Animate background colour (SOLVED)

Is there a way to animate clear_color, to achieve a smooth transition rather than just set it like this?

msg.post("@render:", "clear_color", { color = vmath.vector4(r,g,b,1) } )

I get this error when trying to animate it:

go.animate can only animate instances within the same collection.

I can think of workarounds (using a timer or updating it inside update()), but I’m spoilt using go.animate for everything! :slight_smile:

Use a custom render script and animate background color in the update() function. You can also setup a rectangular fullscreen game object and animate it’s color using a custom shader.

2 Likes

I’m trying this one. With a 64x64 STRETCHED white sprite tinted with:

go.animate("#sprite", "tint", go.PLAYBACK_ONCE_FORWARD, col, go.EASING_LINEAR, duration, delay )

Pray for me. :slight_smile:

You should try this.

go.property("tinting", vmath.vector4(0, 0, 0, 0))
function animate (self)
self.animate = true 
go.animate(".", "tinting". -- the classic animate, function()
self.animate = false
end)
end 

function update(self, dt) 
if self.animate then 
--set clear color to current tint value using msg.post
end
end 
1 Like

That’s cool! How would I get the current tint value, though?

Just do
print(self.tinting) :grinning:

1 Like

I meant the actual vector4 value for the tint? I wanted to avoid calculating that myself, especially using specific easing.

The go.property() is a property which is available on the script instance. You can set the initial value from the script, edit it in the Editor, and animate it in the script.

To get the current tint just do:

msg.post("@render:", "clear_color", { color = self.tinting } )
4 Likes

Blimey, I didn’t realise it was that simple! Thanks guys, the 64x64 stretched bitmap is a gonner!

Edit: I can confirm this is genius, and works perfectly.

3 Likes