From HTML menu to first person


#1

Ok well while i work on my scene changing menu i want a menu to be plausible for any dev in need. So i was wondering is there a way to switch from screen to game (Like keepy Uppy but to fps character) from the menu button to the fps camera. I was thinking i could call the FP camera after clicking play… But im not sure how i am to do this exactly… If someone could help me switch from Menu camera to Player camera after click play let me know.

UPDATE: Ok so basically ive got my screen set up but having 2 screens set up breaks the game completely so for now i have the menu camera turned off until someone sends some feedback or i come up with a script that disables the fps camera then calls it back when u click play.
https://playcanvas.com/editor/scene/722434


#2

The simplest solution would be to disable the menu camera and then enable the FPS camera.

Edit: As you have 2 scenes, just load the FPS scene and unload/destroy the main menu scene.


#3

ok cool thx i will do that


#4

@yaustar Ok so i kind of figured it out but the other scene follows intot the new one and when i click play it duplicates everything in the scene


var changeScene = pc.createScript('global');

// Creates a new Global instance
changeScene.prototype.initialize = function () {
    // initialize current root to first scene loaded
    this.currentRoot = this.app.getSceneUrl();
    this.currentLevel = 0;
    this.levels = [
        722434,
        723038
    ];
};

changeScene.prototype.update = function (dt) {
    if (this.app.keyboard.wasPressed(pc.KEY_ENTER)) {
        this.loadLevel(this.currentLevel);
    }
};

changeScene.prototype.loadLevel = function(level) {


    this.app.loadSceneHierarchy(this.levels[level]+'.json', function(err, entity) {
    });
};

changeScene.prototype.nextLevel = function() {
    this.loadLevel((this.currentLevel + 1) % this.levels.length);
};

I got some help to write this small thing because i got confused but for some reason the previous scene follows me in :frowning:


#5

Have you looked at the changing scenes example? https://developer.playcanvas.com/en/tutorials/changing-scenes/


#6

Yes i seen that example but its time based and i don’t understand where the scene is being disabled im working on destroying the scene when the other loads…

changeScene.prototype.destroyLevel = function(level) {
  this.app.destroySceneHierarchy(this.levels[level]+'.json', function(sceneUrl, levels){
      
  });  
};

This isnt working i dont know why it isnt showing any errors and the console shows it runs so i dont understand what im doing wrong
https://playcanvas.com/editor/code/605986?tabs=18145630 @yaustar


#7

Also it says this:
31%20AM%20-%20Edited
But i dont have a script called changingScenes…
Also Also i have these to types:

changeScene.prototype.changeScenes = function() {
  var oldHierarchy = this.app.root.findByName('Root');
    this.loadScene (this.sceneUrl, function () {
        
    
        oldHierarchy.destroy ();
    });
};

  changeScene.prototype.destroyLevel = function(level) {
  this.app.destroySceneHierarchy(this.levels[level]+'.json', function(sceneUrl, levels){
      
  });  
};

I have it all correct but it isnt working no errors no problems everything is 202020 But it still follows into the new scene…
Im thinking of switching the code to to disable the previous scene but im not sure to disable a scene but i can disable various assets… So if i disable one asset at a time would that be fine?
EDIT: Also here is another example of what i mean by disabling them one by one (Which isnt working either)

        oldHierarchy.destroy ();
        this.app.root.findByName('Camera1');
        this.camera1 = this.asset.disable;
        this.app.root.findByName('MenuScreen');
        this.MenuScreen = this.asset.disable;

EDIT 2: Ok now im trying to disable the scene by attribute

changeScene.attributes.add('entity', {
    type: 'entity'
});

So how would i disable it using the attr? @yaustar


#8

Please see: I still don't get how to make a main menu