[英]How to connect Phaser with Cordova
我正在使用Visual Studio 2015開發html5游戲,並下載了Phaser 2.4.6,並試圖獲取一個APK。 我可以取出,但相位器無法加載...
HTML
<body>
<script src="cordova.js"></script>
<script src="scripts/platformOverrides.js"></script>
<script src="scripts/src/Phaser.js"></script>
<script src="scripts/index.js"></script>
</body>
index.js
document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false );
function onDeviceReady()
{
document.addEventListener( 'pause', onPause.bind( this ), false );
document.addEventListener('resume', onResume.bind(this), false);
var game = new Phaser.GAMES(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
alert("Phaser Going Called...");
};
我沒有收到啟動相位器的警報消息。
我下載了VS 2015 Update 1,並在Visual Studio中安裝了對Apache Cordova的支持所需的位。
使用新的項目模板,我得到了以下index.html :
<!DOCTYPE html>
<html>
<head>
<!--
Customize the content security policy in the meta tag below as needed. Add 'unsafe-inline' to default-src to enable inline JavaScript.
For details, see http://go.microsoft.com/fwlink/?LinkID=617521
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>SimplePhaserTest</title>
</head>
<body>
<div class="app">
<p id="deviceready" class="event">Connecting to Device</p>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="scripts/platformOverrides.js"></script>
<script src="scripts/phaser.min.js"></script>
<script type="text/javascript" src="scripts/index.js"></script>
</body>
</html>
index.js包含以下內容:
// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkID=397704
// To debug code on page load in Ripple or on Android devices/emulators: launch your app, set breakpoints,
// and then run "window.location.reload()" in the JavaScript Console.
(function () {
"use strict";
document.addEventListener('deviceready', onDeviceReady.bind(this), false);
function onDeviceReady() {
// Handle the Cordova pause and resume events
document.addEventListener('pause', onPause.bind(this), false);
document.addEventListener('resume', onResume.bind(this), false);
// TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.
var element = document.getElementById("deviceready");
element.innerHTML = 'Device Ready';
element.className += ' ready';
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create })
alert("Phaser Going Called ...");
};
function preload() {
};
function create() {
};
function onPause() {
// TODO: This application has been suspended. Save application state here.
};
function onResume() {
// TODO: This application has been reactivated. Restore application state here.
};
})();
在本地運行此程序,然后在Android設備(Galaxy S4)上運行,將產生預期的警報消息。
提出這個問題可能只是一些問題,但是我在您的代碼中看到的一些問題都在您的游戲創建中:
var game = new Phaser.GAMES(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
那應該是new Phaser.Game(
,並且您要將其添加到現有的div
,其ID為phaser-example
,但示例HTML中不存在。
它也應該在瀏覽器new Phaser.GAMES
代碼感到窒息,所以我感到困惑,為什么您也不會在那里看到問題。
如果有幫助,我還將在Git存儲庫中提供上述代碼的一個有效示例(鏈接到特定提交,以防將來擴展存儲庫)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.