Hi, I’ve seen in a few places that the recommended way to embed a Playcanvas game into a website is via an iframe but I can’t currently do that on the project I’m working on as it adds more dependencies that can’t be there. I can’t show the website because its for a client, but I can describe the issue. The webpage is currently setup like this with an iframe and it works great. the iframe fills the section styling perfectly:
Now, this doesn’t work whenever I try and embed it this way by dropping the scripts into the section that has the css to constrain the game. notice that this also includes the settings and the engine in the head:
Whenever I do it this way, the whole website background turns gray (you know that Playcanvas gray color) and then all of the html sits on top of that gray color and the game never launches in any visible way. Let me know if anyone has a solution to this. I know its a lot. Thanks in advance.
It’s as bit of tricky one. Haven’t done this before but the way I would approach it is to create a div as a wrapper for the canvas and change __start__.js to create the canvas as a child of that div instead of the document body.
Okay I’ll give it a try. So you’re saying that that html setup I have there in the second example should work as long as I fix how the canvas is parented in the javascript?
odd… now I’m getting 403 errors that the page is having trouble loading my game all together. is it not as simple as dropping the scripts in with the index file? this is how the project is setup (except for the Archive. that is just a zipped version of the project)
That was a silly mistake on my end. Not sure where those files went when I was transferring everything over haha. Now it still seems like its having some problems finding the config file? Here is the console and the file structure yet again:
Okay, I had a proper look at this and it’s going to need a modification to the engine for this scenario to work as the engine assumes it will be in an iframe.
It’s doable with a monkey patch though, it just feels a bit hacky
Is this something yall are planning on being possible in the future with updates to the engine or should I try the hacky way? I have no experience with monkey patches but if you have an idea I’d love to hear it. Otherwise I’ll start taking a whack at it. I’ve just been trying different things within the start.js file up until now
Put this together as in, show how to get to what you have there?
The reason is we’re trying to cut down on pulling from other web pages. The pipeline this will end up landing in already relies on so many different things to pull from, I don’t currently have authorization to add more links out of the build instead of just building within the page itself.
Yes, I will do a GitHub repo and you can see the commit changes
When you say other, do you mean external or just in general? I was thinking the iframe would link to a PlayCanvas build host on the same server/site as the page. Is that not permitted?
Definitely cannot do external, but I believe in general. I’d have to check with my team on that though. We often work in pretty low bandwidth environments so I do wonder if that would impact performance at all (because it’d be an extra call to a server) rather than having it baked into the page.
Thank you so much for all the help man. I look forward to hearing from you tomorrow
That’s interesting Is it the number of network calls or the data size that matters or both in these environments?
The reason I ask is because if the number of networks is more important, we could embed the files/source in base64 URLs. However, that increases the size.