How do I lerp layer background colors and opacity correctly?

0 favourites
  • 5 posts
From the Asset Store
Stack as many colored blocks as possible to create the biggest structure ever! Overcome your limits!
  • So I have the following code running non-stop during a cut-scene

    -> System: Set layer "Lighting" background color to rgb(lerp(51,3,0.1), lerp(14,8,0.1), lerp(9,21,0.1))

    -> System: Set layer "Lighting" opacity to lerp(80,98,0.1)

    However, the colors aren't correct and it seems like the opacity stops at 81.8 for some bizarre reason. The event itself looks like this ...

    I think I'm probably doing this very wrong, so could any wizards please show me the light? Thank you so much!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You probably want to use tween instead of lerp.

    The final value in lerp is a percentage point between a and b. If a and b don't change and you use a fixed number for the lerp value, it's going to give you a fixed value in return.

    Example: set position lerp(currentposition,targetposition,0.5) means halfway to the target position. The next tick it is run, go halfway again. Note the second time it is smaller, since you're closer. The amount will get less and less, and you never actually get to the target, only halfway closer each tick.

    In your case, lerp(80, 98, 0.1) means 10% of the way from 80 to 98, which is 81.8. If nothing in the inputs change, it will always be 81.8.

  • Thank you so much for replying oosyrag, appreciate it.

    This sounds perfect, however (as far as I know) we can't tween a background color on a layer?

  • You can tween (value) anything that is a number. The tween behavior needs to be on an object though, you can use an invisible helper object if there are no other suitable ones.

    Here's an example.

    dropbox.com/s/yphcbehsh9bwcjn/tweenandsineexample.c3p

    I also added a second layout using sine - another way to do it in case you want a cyclical change. Of course you can also just add an event to play the tween again when the first one completes. Up to you!

  • Speaking of Tween, the plug has settings to tween colors, so you could use a sprite, or tiled bg instead of the layer.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)