add this code in your chracher (game start) start scene always added. this.scene().addLevel('scene1'); //scene names this.scene().addLevel('scene2'); this.scene().addLevel('finish'); ------------------------------------------------------------------ random scene and finish sample scn1=Math.round(Math.random() *9)+1; //you have 10 scenes. names are 1,2,3,..10 scn2=Math.round(Math.random() *9)+1; this.scene().addLevel(String(scn1)); //random scene this.scene().addLevel(String(scn2)); this.scene().addLevel('finish'); //finish is scene name
or guys who couldn't make addScene() working. You have to follow this rule. *** You need to add final scene in the end, its damn compulsory else it won't work *** For example this.scene().addLevel('Scene1'); this.scene().addLevel('Scene2'); this.scene().addLevel('Finish'); Example 2 this.scene().addLevel('Scene3'); this.scene().addLevel('Scene4'); this.scene().addLevel('Finish');
For me it is working without the finish part. So I basically randomized everything. The only issue right now is that I want to do it in parts. So let's say that I have 4 sections of 5 scenes, every scene is 100 frames (in my game every scene is a level with a finish). First I want the first 5 scenes/levels to randomize until 2000 frames. So looped 4 times. Same with second and third section. and then i want the last section to randomize infinitly. Anyone can help? Thanks
Thanks to everyone for the sample code and help. If anyone is having a level endlessly repeating issue, this is what I used to get a consistent randomization without it getting stuck in an endless same level loop. function signal(name, value, sender){ scn1=Math.round(Math.random() *8)+2; // I used *8)+2 because I want a value of 2-10 but never 1 scn2=Math.round(Math.random() *8)+2; scn3=Math.round(Math.random() *8)+2; scn4=Math.round(Math.random() *8)+2; scn5=Math.round(Math.random() *8)+2; scn6=Math.round(Math.random() *8)+2; scn7=Math.round(Math.random() *8)+2; scn8=Math.round(Math.random() *8)+2; scn9=Math.round(Math.random() *8)+2; this.scene().addLevel(String(scn1)); if (scn1!=scn2){this.scene().addLevel(String(scn2));} if (scn2!=scn3){this.scene().addLevel(String(scn3));} if (scn3!=scn4){this.scene().addLevel(String(scn4));} if (scn4!=scn5){this.scene().addLevel(String(scn5));} if (scn5!=scn6){this.scene().addLevel(String(scn6));} if (scn6!=scn7){this.scene().addLevel(String(scn7));} if (scn7!=scn8){this.scene().addLevel(String(scn8));} if (scn8!=scn9){this.scene().addLevel(String(scn9));} } It ends up looping back to my 1st scene out of 10 and loops new randomizations It may be a bit hacky, but hopefully someone finds it useful.
do u have eny example of this: if i go back to load scene, bb3 is deleting previous scenes and need to load again them
this.scene().addLevel(String(Math.round(Math.random() *25)+17)); hi i need to understand how this line calculate, could somebody explain it pls