Hi everyone,
Id like to have a very simple explainer on how to play my game. It should just consist of one image/page and dissapear on a click/touch.
I allready tried with some UI buttons and a script on changing scenes, but I have the feeling its loading quite slow. Does someone happen to have a more neat setup than this? (also for some reason, when it moves from the UI scene to Scene1 which is the game itself it replaces my opcaity materials with solids :S )
var ChangingScenes = pc.createScript(‘changingScenes’);
ChangingScenes.attributes.add(“scene1”, {type: “string”, default: “0”, title: “Scene ID to Load”});
ChangingScenes.attributes.add(“scene2”, {type: “string”, default: “0”, title: “Scene ID to Load”});
ChangingScenes.attributes.add(“scene3”, {type: “string”, default: “0”, title: “Scene ID to Load”});
ChangingScenes.prototype.initialize = function(dt) {
// Change scenes on button click
this.app.root.findByName(‘Change scene 1’).element.on(‘click’, function (event) {
this.changeScenes(this.scene1);
}, this);
this.app.root.findByName('Change scene 2').element.on('click', function (event) {
this.changeScenes(this.scene2);
}, this);
this.app.root.findByName('Change scene 3').element.on('click', function (event) {
this.changeScenes(this.scene3);
}, this);
};
ChangingScenes.prototype.changeScenes = function(sceneId) {
// Get a reference to the current root object
var oldHierarchy = this.app.root.findByName (‘Root’);
// Load the new scene. The scene ID is found by loading the scene in the editor and
// taking the number from the URL
// e.g. If the URL when Scene 1 is loaded is: https://playcanvas.com/editor/scene/475211
// The ID is the number on the end (475211)
this.loadScene (sceneId, function () {
// Once the new scene has been loaded, destroy the old one
oldHierarchy.destroy ();
});
};
ChangingScenes.prototype.loadScene = function (id, callback) {
// Get the path to the scene
var url = id + “.json”;
// Load the scenes entity hierarchy
this.app.loadSceneHierarchy(url, function (err, parent) {
if (!err) {
callback(parent);
} else {
console.error (err);
}
});
};