can you please explain step by step how to include the playcanvas script in an Angular 2 component?
if i simply include the scripts in the head and two scripts start.js and loading.js in the component, the canvas starts correctly the first time but whe i open the view the second time i have lot of errors:
script registry already has 'boundingBoxShape' script, define 'swap' method for new script type to enable code hot swapping
script registry already has 'boundingSphereShape' script, define 'swap' method for new script type to enable code hot swapping
script registry already has 'shapePicker' script, define 'swap' method for new script type to enable code hot swapping
[and other errors like those]
Can you explain a bit more what youâre trying to do? Those errors mean that you are trying to add those scripts to the script registry again which probably means that your playcanvas application still exists in the background Iâm guessing.
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "__start__.js";
this.elementRef.nativeElement.appendChild(s);
var t = document.createElement("script");
t.type = "text/javascript";
t.src = "__loading__.js";
this.elementRef.nativeElement.appendChild(t);
it works when i open the view the first time, but the second time i have those errors because, as you say, the aplication still exists.
can you please explain step by step how to include the playcanvas script in an Angular 2 component?
I donât really know how Angular 2 works. But what Iâm guessing is that you are loading this view which re-includes the __start__.js and __loading__.js scripts. You could either not do that and include those scripts in the head of your page once, or make sure that when youâre leaving the view you destroy the existing application.
perfect, iâll try to destroy.
another error that i have occasionally is:
Uncaught TypeError: Cannot read property 'on' of null
at __loading__.js:107
at Object.createLoadingScreen (playcanvas-stable.min.js:791)
at __loading__.js:1
code at 107 row:
app.on('preload:end', function () {
app.off('preload:progress');
});
I think is also linked with angular. Does not happen always, i think only when the âappâ is not yet created. Do you have any suggestions?
You donât have to use the __start__.js and __loading__.js scripts if youâre self hosting this. You could just read the code in those files so you get whatâs going on and handle the app creation / destruction yourself where it suits you.
Is it possible for you to host your application somewhere and post a link here? Itâs really hard to figure out whatâs wrong with some arbitrary angular application without looking at some code
Alternatively you could zip everything up and PM me a link so I can download it and try it locally.