How do I use/mimic multi-threading?

0 favourites
  • 7 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Hello!

    I need to plot a sine wave at high speeds.

    I used the value from a Sine behavior, but sometimes it is not consistent and the wave is messed up for a few frames then returns back to normal (probably affected by framerate).

    I tried to calculate the value every 0.1sec, which is more consistent, but the Sine behavior was smoother.

    Is there a way to make a function run in its own worker/thread.. and get the result to a variable, then draw it?

    (The Sin is just the base for other equations; so when the Sin is Slow or Not consistent, the other equations break).

  • All behaviors are framerate-independent, Sine including. Unless fps drop below 30, it should produce consistent results.

    Can you post your project file, demonstrating the problem? Maybe the framerate is not the issue.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • All behaviors are framerate-independent, Sine including. Unless fps drop below 30, it should produce consistent results.

    It is below 30..

    Can you post your project file, demonstrating the problem? Maybe the framerate is not the issue.

    OK. I will do so soon.

    Thank you.

  • Oh, Construct is not supposed to run at fps <30. The game will slow down because the delta-time (dt) can't be greater than 0.0333

    Of course the best solution would be fixing whatever is causing bad performance. If this is not possible, then I guess you will have do sin calculations in events, without Sine behavior. And you'll have to use the device clock to get the actual delta-time value.

  • Since you said you’re plotting it you can just use a sin() equation:

    Value = amplitude*sin(frequency*t+phase)

    As a simple example say you want to plot a sine wave you can do that with a loop:

    Start of layout

    Repeat 640 times

    — create sprite at (loopindex, 240+100*sin(10*loopindex))

    Or if you wanted to plot a portion of it each frame you could do:

    variable x =0

    variable prevtime=0

    Repeat (time-prevtime)*60 times

    — add 1/60 to prevtime

    — add 0.1 to x

    — create sprite at (x, 240+sin(10*x))

  • There'S a webworker example

  • There'S a webworker example

    Thank you, that's what I was looking for.

    I solved the original issue using another method, but the worker example should come in handy.

    Thank you all for the help :)

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