Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling functions from within another - javascript
    primarykey
    data
    text
    <p>I'm relatively new to javascript and having a couple of issues that I'm hoping you can help with. I'm utilizing the fabric library with canvas to create an animation of sorts.</p> <p>I have a function that is called when the relevant button is pressed:</p> <pre><code>//for starting the animation startSim.onclick = function(){ //obtain speed value from the control panel. var speed = 10000 / (new Number(speedControl.value)); //stuff //animation process object.animate('top', '+='+canvas.height,{ duration: speed, abort: function(){ var returnedBool; //Pause is pressed, simulation pauses if(pause){ //stuff } //restart required if(restart){ //stuff } //option here to save data? return returnedBool; },//end abort callback onChange: canvas.renderAll.bind(canvas), onComplete: function(){ //stuff } });//end animate callback }; </code></pre> <p>What I'd like to do is call certain other functions while the above animation is active.</p> <p>I know how I'd like to do this using Java or C++ but I can't seem to call the function.</p> <p>I have a display panel that should output various information - as the animation completes variables will change and I'd like them to be output on the screen and be updated as they change.</p> <p>I'm testing with a simple function:</p> <pre><code> function updateInfoPanel(testSpeed){ var test = document.getElementById('currentSpeed'); test.innerHTML = test.innerHTML + testSpeed; } </code></pre> <p>I think I need to call this in the main animate loop, if I call it before it's fine but obviously only displays the variable once. Could someone tell me where I'm going wrong please?</p> <p>I also have a basic collision detection function that works but not within the animate loop and I think these problems are linked.</p> <p>Many thanks for any help.</p> <p>I removed the unnecessary parts of the code to save space.</p> <p>So I've just tried to use a function as the result of onChange:</p> <pre><code>onChange: function(){ canvas.renderAll.bind(canvas); updateInfoPanel(speed); }, </code></pre> <p>This doesn't present syntax errors but the animation no lingers runs although the speed variable does update in the info panel very quickly. :(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload