解决方案:运行游戏本地文件(file:///)构造2 [英] Solution: Run game local (file:///) Construct 2

查看:1052
本文介绍了解决方案:运行游戏本地文件(file:///)构造2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近不得不构建一个移动应用程序,该应用程序可以下载使用Construct 2构建的游戏并在本地运行,我的解决方案是以不同的方式处理游戏数据和声音.这是我的解决方案:

I've recentelly had to build a mobile app that could download games build with Construct 2 and run locally, the solution I've got is handle the game data and sounds in a different way. And here is my solution:

推荐答案

1-未选中minify选项即可导出游戏

1- Export your game with the minify option unchecked

2-更改Construct处理声音的方式,为此,我们需要打开index.html并在 代码之后添加:

2- Change the way Construct handle sounds, to do that we need to open the index.html and add right after the code:

<div style="display:none;">
<script>
window.playAudioAux = function(url){
    var output = url.substr(0, url.lastIndexOf('.')) || url;
    var url1 = output+'.ogg';
    var url2 = output+'.mp3';
    var url3 = output+'.m4a';
    document.getElementById('myAudioogg').src = url1;
    document.getElementById('myAudiompeg').src = url2;
    document.getElementById('myAudiomp4').src = url3;
    document.getElementById('myAudio').src = url3;
    document.getElementById('myAudio').load();
    document.getElementById('myAudio').play();
}
</script>
<audio id="myAudio" controls>
  <source id="myAudioogg" src="" type="audio/ogg">
  <source id="myAudiompeg" src="" type="audio/mpeg">
  <source id="myAudiomp4" src="" type="audio/mp4">
    Your browser does not support the audio element.
</audio>
</div>

这将创建一种运行音频的新方法.现在我们必须更改 c2runtime.js 调用声音的位置,所以找到:

This will create a new way to run audio. And now we have to change the c2runtime.js where it calls the sounds, so find:

function C2AudioInstance(buffer_, tag_)
{

然后在其后添加

playAudioAux(buffer_.src); return;

这将停止对Construct的常规调用,并调用我们刚刚添加到index.html上的函数

This will stop the normal call of Construct and call the function that we just added on the index.html

3-大多数(也许所有)浏览器都将来自本地的请求视为安全问题,因此我们必须以其他方式加载该游戏 data.js ,然后将其打开以复制其内容.同样在 c2runtime.js 内部,在requestProjectData函数中找到以下代码:

3- Most(maybe all) browsers see requests from local as a security problem so we have to load that game data.js in a different way, open it so you can copy its content. Also inside c2runtime.js find the following code inside requestProjectData function:

xhr.open("GET", datajs_filename, true);
var supportsJsonResponse = false;

然后添加以下代码:

self.loadProject(FULL_CONTENT_INSIDE_YOUR_DATA.JS); return;

这将加载您的游戏内容并取消加载data.js的请求.

This will load your game content and cancel the request to load data.js.

4-内部index.html注释有关在本地运行游戏的警报,如下所示:

4- Inside index.html comment the alert about running the game locally like this:

//alert("Exported games won't work until you upload them. (When running on the file:/// protocol, browsers block many features from working for security reasons.)");

就是这样! :D,它在firefox,android webview等内部运行良好.出于安全原因,唯一仍不运行它的是Chrome ...

That is it! :D, It runs fine inside firefox, android webview etc. The only one that still doest run it is Chrome for security reasons...

希望它可以帮助任何遇到这种问题的人.

Hope it helps anyone with this kind of problem.

这篇关于解决方案:运行游戏本地文件(file:///)构造2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆