Jump to content

How do I create Start, Stop and Restart buttons?


Recommended Posts

How do I create Start, Stop and Restart buttons?
I'm learning babylonjs to teaching it for my physics stutents. 
My plan is to teaching to create physics simulations like phet colorado sims but in 3d.
First, I need a standard GUI with Play, Stop and Restart buttons that works with physics engines.
I made a playground for sample it: http://www.babylonjs-playground.com/#1ADV28#67 click two time run for wok after castor error. I want to stop the sphere free fall and restart the scene.
Which functions or commands do I need to use for it?

Rafael J.

Link to comment
Share on other sites

Where you are using function in your castorGUI objects, this is a callback function. there is no value in using function() and you won't get and error. Simply create 3 functions to start, stop, restart your animations, and replace "function()" in your options with the name of the new animation functions.



Link to comment
Share on other sites


It's work, but it isn't so easy for complex scene. 

I made a code something like your code:

var time = 0;
var start  = false;
var force = 0.0;
var mass = 0.0;

//button start:

document.getElementById("Start").onclick=function(){play = true};

//button restart;

document.getElementById("Restart").onclick=function(){play = false};

   scene.registerBeforeRender(function () {

          force = document.getElementById("Edit1").value;
    mass = document.getElementById("Edit2").value;
        acceleration = force  / mass;
        if (play) {
        time += 1;
        sphere.position.x += acceleraton * time *time  /2;
        else {
        time = 0;
        sphere.position.x = 0;

I'm thinking about a second way by change the scene and rechange to first scene for reload, like this solution: http://www.babylonjs-playground.com/#1B3R9A#2

I think that babylonjs need something like:

Or a set of common functions for scene control, like find in others engines.

For example, in blender game engine we have:


Rafael J.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...