How do I smoothly ramp an effect parameter value?

  • Hi, I'm wondering how I to ramp value so that it moves smoothly from, for example, 1 to 100, rather than just an abrupt jump from 1 to 100.

    Specifically, I want to blur the title text of my game on the start menu once the player selects "start". The title text has the BlurVertical effect on it, I can trigger it to jump from 0.1 to 100, is there a way to make the effect ramp to the higher value?

    thanks,

    Matt

  • I've used Groups to deal with such:

    Group "BlurIn" (disabled at start)

    -every tick/x seconds -> set blur effect to blur effect plus x

    -If blur effect > 100 disable Group "BlurIn"

    Then when you want it to blur just set the group to be enabled. Can make another group that does the opposite.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Donic Dawkins

    Alternatively, for an eased effect, you can create a global variable called BlurValue and set it to 0. Create an instance variable on your text object BlurOn with a value of 0. Add these events:

    On "Start" object clicked => set text.BlurOn to 1

    If text.BlurOn = 1 => set text effect parameter to BlurValue, set BlurValue to lerp(BlurValue,100,1-0.3^dt)

    I hope this helps

  • HI badmoodtaylor and SimoneT,

    Both seems like good approaches, thanks for suggesting. I like the idea of Groups that get turned on/off, and I also like the idea of using the lerp function for easing.

    However couldn't get either to work

    badmoodtaylor, I may have the math wrong. I tried it several ways, how would I properly state "BlurEffect plus x"?

    SimoneT, not sure what isn't working here. Pretty sure I have my global and instance variables set right, and I copied and pasted your values for lerp.

    thanks,

    Matt

  • In your screen shot your group is disabled. You don't want that—it can't get enabled at runtime. Right click on it, click on edit, un-check "active at start".

    Sorry if my terms mislead you—lackadaisically I used 'disabled' instead of 'not active'

  • Event4: You are setting BlurOn to the BlurValue. You need to set the effect value to BlurValue.

  • Here is one with regular blur and text blur—I might like regular better but your preference. You can mess with the speed of the lerp one by changing the "0.08" but make sure you change it in both actions

    https://www.dropbox.com/s/h9p6gpi07uisf ... .capx?dl=0

  • Thanks for file badmoodtaylor but can't open as I'm still on the last stable release (r233). I made the group inactive rather than disabled and the effect occurred, but did not ramp to 100, jumped to the highest value.

    blackhornet, made the change as you suggested and the code works. Not sure of how to manipulate the lerp values. The manual states this as the definition of lerp:

    lerp(a, b, x) Linear interpolation of a to b by x. Calculates a + x * (b - a).

    So for my example a = BlurValue, b = time it takes to come to full value (?), and x = amount of blur to add (?).

    thanks,

    M

  • Thanks for file badmoodtaylor but can't open as I'm still on the last stable release (r233)...

    Ah, that's really annoying because I only updated to open someone else's capx I was trying to help

  • Donic Dawkins

    [quote:28xoto88]So for my example a = BlurValue, b = time it takes to come to full value (?), and x = amount of blur to add (?).

    If I understand correctly, this should be how it works:

    a = Current Value

    b = your target value

    x = how big the steps are

  • x is a increasing/decreasing number from 0 to 1 (or 1 to zero)

    you have to increase/decrease x in some system

    look at my example for 1 possibility

  • x is a increasing/decreasing number from 0 to 1 (or 1 to zero)

    you have to increase/decrease x in some system

    look at my example for 1 possibility

    True in the traditional lerp way, but not in the gradual decline effect where x is a constant (somewhere around 0.04) and the a is updated to the current location. This will move fast at first and slow as it goes but never reach the exact b, so much test for b-1, or somewhere really close.

    Is there a way to save as an older version capx? Mine had both examples, think it would be helpful

  • Ah, but that is why i used 'cube' in stead of 'lerp'. Cube is just a lerp with 4 points. The easy way to make a easyIn/easyOut lerp without plugins, when dealing with a static end and a static start.

    Personal, for myself, i would use TweenLite, either to feed a lerpfactor to a lerp, or to use it as intended.

  • badmoodtaylor, I hear ya, all good.

    99Instances2Go, lovely code, thanks for posting. Timer seems like a good way to go, still going through your code but think I get it...

    cheers,

    M

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