我下載了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 repo(鏈接到特定提交,以防將來擴展回購時)中的上述代碼的工作示例。
上面兩個不同的文件是?或者是你的HTML文件?我也試圖清理你的問題,但我不確定你的意思是什麼時候你說「我可以拿出來但Phaser沒有加載......」 –
是的上面我們有2個不同的文件1)Html 2)Javascript我在HTML頁面中加載了cordova,platformOverrides,Phaser,index,使用index.js我嘗試使用上面的相位器代碼啓動相位器,但它並沒有啓動,並且在啓動的下方我們有一個不在遊戲中的警告框 –
如果你只是在瀏覽器中運行它,它是否工作?任何控制檯錯誤?我想你想把遊戲附加到一個不存在的div上。 –