RafaelJ Posted June 29, 2016 Share Posted June 29, 2016 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. Quote Link to comment Share on other sites More sharing options...
RafaelJ Posted June 29, 2016 Author Share Posted June 29, 2016 Hi, I made updates in my playground with things I learned with Dad72 member. http://www.babylonjs-playground.com/#1ADV28#68, this don't have the error. I need the functions for the buttons work. Thanks, Rafael J. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 29, 2016 Share Posted June 29, 2016 @Dad72 will be able to help you soon Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 29, 2016 Share Posted June 29, 2016 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 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 29, 2016 Share Posted June 29, 2016 Hello, try this: http://www.babylonjs-playground.com/#1ADV28#69 I add 'spherefisica' in global variable, and I use getPhysicsImpostor().setParam( 'mass', num); for play and stop. Quote Link to comment Share on other sites More sharing options...
RafaelJ Posted June 30, 2016 Author Share Posted June 30, 2016 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.