Kilombo Posted June 17, 2014 Share Posted June 17, 2014 Hello community, I'm in need of help with something on my project. I need do draw a new scene in the same scene stuck in a while loop (while the option exit isn't pressed). By that I mean, that i would like to clear the all screen when this function is started, then, when exit is pressed, the "state machine" would come back to the main scene. I'm not beeing able to find any function to do this. Any suggestions ? Thanks in advance, Quote Link to comment Share on other sites More sharing options...
Temechon Posted June 17, 2014 Share Posted June 17, 2014 Hi, Are you working on a menu or something like that ? Could you give us an example or a mockup (even in paint) to help us understand ? Anyway, would set all meshes in your "all scene" to visible=false be enough ?while(exitOptionNotSelected) { allScene.meshes.forEach(function(mesh) { mesh.isVisible = false; }}allScene.meshes.forEach(function(mesh) { mesh.isVisible = true;} Quote Link to comment Share on other sites More sharing options...
Kilombo Posted June 17, 2014 Author Share Posted June 17, 2014 Thanks Temechon. Go to my project in http://www.andromedaquest.tk enter with username: xpto and password: xpto (I'll keep the user active for the next 24 hours at least). When you hoover the planets, you can see the option "colonize planets".And if a planet is already colonized, what will apear is base details. So... When that option is pressed the screen has to change to the "base" screen, I have to draw a new floor, with new texture, the structures and anything else. Then when the player presses "exit" it will come back to the "space ambient". Quote Link to comment Share on other sites More sharing options...
Temechon Posted June 17, 2014 Share Posted June 17, 2014 Nice work ! For your problem, I would save the player position in the space scene, and completely destroy it (scene.dispose()), and finally build your base scene. On exit, retrieve the player position from indexDb (for example, or localStorage, or memory or whatever) and load your space scene as you do it in your init game. Quote Link to comment Share on other sites More sharing options...
Kilombo Posted June 17, 2014 Author Share Posted June 17, 2014 Thanks Temechon. That's a good idea, it's so obvious. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 17, 2014 Share Posted June 17, 2014 Hi gang. Couldn't the space scene be in engine.scenes[0], and when a base needs to be assembled, do it in engine.scenes[1], and switch to it? Then switch back to engine.scenes[0] upon base exit? *shrug* I have never tried scene switching... and know nothing about it, but maybe easier? If you do tests on scene switching, Kilombo, report your discoveries to us, ok? Cool. Quote Link to comment Share on other sites More sharing options...
Kilombo Posted June 17, 2014 Author Share Posted June 17, 2014 In fact, that looks really interesting... Hmmm. one array of scene objects That's one great idea. Where did that come from, eheheh I'll try it and report. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 17, 2014 Share Posted June 17, 2014 That's Deltakosh's idea. The babylon engine is already designed for multiple scenes. How one goes about switching between engine.scenes[0] and engine.scenes[1]... I have no idea. But others might. And you know Deltakosh and the other big dogs around here. If its possible, they will install a function to help you do it. http://www.babylonjs.com/playground/#1IZVFS The playground makes the first scene FOR you... as the first alert indicates. Then I make another scene, and the second alert tells us it worked. Kilombo 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 18, 2014 Share Posted June 18, 2014 Because you control the renderLoop, you can just load all your scenes and then:engine.runRenderLoop(function() { engine.scenes[currentSceneIndex].render();}); Kilombo 1 Quote Link to comment Share on other sites More sharing options...
gryff Posted June 18, 2014 Share Posted June 18, 2014 you can just load all your scenes I'm curious - in fact quite overwhelmed - about the code that allows loading "all your scenes" ? Not something I have seen in any tuts - and how does it handle all the textures you might be loading? cheers, gryff Quote Link to comment Share on other sites More sharing options...
Kilombo Posted June 18, 2014 Author Share Posted June 18, 2014 It's implemented. Quite easy actually. And works amazingly well.I load the scenes in a "sta.rt" function by calling two diferent funtions (each calls his scenes[0] and scenes[1]).Then, in the render loop i use some global booleans two trigger the rendering between them.There's the example code.function start() { canvas = document.getElementById("renderCanvas"); var info1 = document.getElementById("info1"); var info2 = document.getElementById("info2"); var shipposition = document.getElementById("shipposition"); if (!BABYLON.Engine.isSupported()) { window.alert('Browser not supported'); } else { renderCanvas = document.getElementById("renderCanvas"); engine = new BABYLON.Engine(renderCanvas, true); var systems = new Array(); systems = sceneSpace(); sceneBase(); };engine.runRenderLoop(function() {if (base === true){ space = false; scenes[1].render(); } if (space === true){ base = false; scenes[0].render(); } });Thanks for the help guys. 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.