How do I reuse the same calculation for several sprites?

0 favourites
  • 7 posts
From the Asset Store
Several elements of the game interface hidden objects
  • I have an input element (FaderValue) that gives a value from -100 to 0.

    These value are converted in an exponential equation that I want to tinker with to get right, but trial purposes I am happy with it for now:

    round(3.1 * (1 - exp(-0.035 * FaderValue)))

    Now, I need to use the calculated value for several objects in my project. How do I implement this?

    With a variable? Can I set a variable to this equation?

    With a function? With parameters? How should I set that up?

    Any other suggestions?

  • In your case, if the value only is calculated when you change the fader, I'd go with a global variable to store it.

    So, On input -> set global variable to round(3.1 * (1 - exp(-0.035 * FaderValue)))

    This stores the result until you change the input again. So yes, you can set a variable to that equation, just keep in mind it stores the result, not the equation itself.

    As for applying it to several objects in your project, that depends on what exactly you want to do. You could use families and custom actions to handle whatever the objects need to do based on the value. Perhaps a function also does the trick in your case. Most likely either of those will be what you're looking for.

  • Similarly, how can I use a function or a variable to avoid this:

    These 4 lines sets the correct animation frame for two instances of the same sprite. Completing this build, I will eventually have 12 instances of the same sprite, and I believe this can be done without having 24 single lines in the event sheet?

  • As for applying it to several objects in your project, that depends on what exactly you want to do. You could use families and custom actions to handle whatever the objects need to do based on the value. Perhaps a function also does the trick in your case. Most likely either of those will be what you're looking for.

    My use case is the following: I am making a control panel with volume faders, like a simple audio mixing console. I have multiple faders moving along the Y axis, and I have managed to make the "input value" increase linearly from -100 to 0 as the knob is moved up the Y axis.

    Using the equation in question makes sure that the "output values" increase more rapidly in the bottom end of the Y axis and increase slower in the top end. This is preferred performance for a mixing console.

    I could put the equation into every single (there will be 12-16 faders upon finishing this project) faders "output value" calculation, but I want to understand how I can use a variable to store this equation in one place and then reference that location in all the faders. If I later want to adjust the equation ( I will ), then I only have to make the adjustments in one place instead of 12-16 places.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ah, so you can "store" that expression itself in the form of a function, that returns the resulting value. As for the sliders, I'd put them into a family and use custom actions.

    This setup will change the sliders frames at 97 for all sliders. But you can also then add overrides if a specific slider should change at 50 for example.

    I suggest reading into functions and custom actions:

    construct.net/en/make-games/manuals/construct-3/project-primitives/events/functions

    construct.net/en/make-games/manuals/construct-3/project-primitives/events/custom-actions

    Hope this helps!

  • Hope this helps!

    Thanks so much for this, It will speed up my workflow loads!

    The whole thing of variables and functions... It is a bit difficult to wrap my head around it, and to see a couple of examples is very helpful!

  • So, coming back to this:

    I have given the fader a instance variable called indFaderValue (for individual fader value). Now, I need to address these individual values to the the volume parameter of different audio tracks. I have separated audio tracks that are imported into my project.

    Lets say, instance 1 of the fader family needs to adjust/set the volume of the guitar audio track. Instance 2 need to control the volume of the drums track.

    How do I grab the value of a parameter of a certain family member and set the audio volume to that value? I can vision using UID or something like that, but I can not find anywhere this is being addressed? Could anybody show me, maybe with a screenshot, or maybe point me in the direction of some document or youtube video that explains this?

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