简体   繁体   English

如何在HTML5中包含Cordova.js

[英]How to include Cordova.js in HTML5

I would like to convert my HTML5 game to iOS/Android app, I can do it using Phonegap or Cocoon, all tutorials show that we must include cordova.js file into index.html page. 我想将HTML5游戏转换为iOS / Android应用程序,我可以使用Phonegap或Cocoon做到这一点,所有教程都表明我们必须将cordova.js文件包含到index.html页面中。

If I include cordova.js as suggested: 如果我按照建议包括cordova.js:

<html>
<head>
    <script src="cordova.js"></script>
    <script src="js/phaser.min.js"></script>
    <script src="js/game.js"></script>
</head>
</html>

I can see this message: 我可以看到以下消息:

_Uncaught ReferenceError: require is not defined at cordova.js:28_

Also, I have uploaded a project to web server and I get same results. 另外,我已经将项目上载到Web服务器,并且得到了相同的结果。 Downloaded cordova from here https://github.com/apache/cordova-js/blob/master/src/cordova.js 从此处下载的cordova https://github.com/apache/cordova-js/blob/master/src/cordova.js

在此处输入图片说明

It appears that you just copied the cordova.js file straight from GitHub and included it in your project manually. 看来您只是直接从GitHub复制了cordova.js文件,并手动将其包含在项目中。

If you want to use Cordova you should instead be using Node.js to create your project and define your platforms. 如果要使用Cordova,则应改用Node.js创建项目并定义平台。 This in turn will include the full cordova.js file, which includes the require() function. 反过来,这将包括完整的cordova.js文件,其中包括require()函数。

Create your first Cordova app on the official site includes a basic tutorial on getting started, and GameDev Academy has a tutorial on Creating Mobile Games with Phaser 3 and Cordova . 在官方网站上创建您的第一个Cordova应用程序 ,包括入门入门基础知识,而GameDev Academy则提供了有关使用Phaser 3和Cordova创建手机游戏的教程。

Essentially, once you have Cordova tools and requirements installed: 本质上,一旦您安装了Cordova工具和要求:

  1. cordova create projectName to create the new project. cordova create projectName创建新项目。
  2. cd projectName to move into the new project directory. cd projectName移到新的项目目录。
  3. cordova platform add android and/or whatever platforms you want your game to run on. cordova platform add android和/或您要在其上运行游戏的任何平台。
  4. Update the www directory as you normally would for a Phaser game. 像平常使用Phaser游戏一样,更新www目录。 You can follow the GameDev Academy tutorial and use Node.js to install Phaser, or just copy/paste the JS file, whichever you're more comfortable with. 您可以按照GameDev Academy教程进行操作,并使用Node.js安装Phaser,或仅复制/粘贴JS文件,以更满意的方式进行。
  5. cordova build to make sure everything builds. cordova build ,以确保一切都建立。
  6. cordova emulate android to test it in Android, for example, but change as needed for your particular environments. 例如, cordova emulate android以在Android中对其进行测试,但可以根据您的特定环境进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM