Sign in to follow this  
RafaelJ

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?

Thanks,
Rafael J.

Share this post


Link to post
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.

 

DB

Share this post


Link to post
Share on other sites

Hi,

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:
scene.restart();
scene.pause();

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

For example, in blender game engine we have:

bge.logic.KX_SCENE_RESTART
bge.logic.KX_SCENE_SET_SCENE
bge.logic.KX_SCENE_SET_CAMERA
bge.logic.KX_SCENE_ADD_FRONT_SCENE
bge.logic.KX_SCENE_ADD_BACK_SCENE
bge.logic.KX_SCENE_REMOVE_SCENE
bge.logic.KX_SCENE_SUSPEND
bge.logic.KX_SCENE_RESUME

Thanks, 
Rafael J.

 

Share this post


Link to post
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.

Guest
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.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.