简体   繁体   中英

html5 + phaser issues

I'm trying to develop a game using xdk with Phaser library. I have 2 prefabs and I have error in them.

Here is the code of one of them and the html of the game:

 var BasicGame = BasicGame || {}; BasicGame.balls = function(game ,x,y ) { Phaser.Sprite.call(this,game,x,y); this.game=game; this.game.physics.Arcade.enable(this) ; this.anchor.setTo(0.5) ; this.body.velocity = this.game.RandomDataGenerator ; }; BasicGame.balls.prototype = Object.create(Phaser.Sprite.prototype); BasicGame.balls.prototype.constructor = BasicGame.balls ;
 <html> <head> <title>Phaser Full Screen Mobile Example</title> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="chrome=1, IE=9"> <meta name="format-detection" content="telephone=no"> <meta name="HandheldFriendly" content="true" /> <meta name="robots" content="noindex,nofollow" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black" /> <meta name="apple-mobile-web-app-title" content="Phaser App"> <meta name="viewport" content="initial-scale=1 maximum-scale=1 user-scalable=0 minimal-ui" /> <link rel="apple-touch-icon" href="/apple-touch-icon.png"> <!-- non-retina iPhone pre iOS 7 --> <link rel="apple-touch-icon" sizes="57x57" href="icons/app_icon_57x57.png"> <link rel="apple-touch-icon" sizes="60x60" href="icons/app_icon_60x60.png"> <!-- non-retina iPad pre iOS 7 --> <link rel="apple-touch-icon" sizes="72x72" href="icons/app_icon_72x72.png"> <!-- non-retina iPad iOS 7 --> <link rel="apple-touch-icon" sizes="76x76" href="icons/app_icon_76x76.png"> <!-- retina iPhone pre iOS 7 --> <link rel="apple-touch-icon" sizes="114x114" href="icons/app_icon_114x114.png"> <!-- retina iPhone iOS 7 --> <link rel="apple-touch-icon" sizes="120x120" href="icons/app_icon_120x120.png"> <!-- retina iPad pre iOS 7 --> <link rel="apple-touch-icon" sizes="144x144" href="icons/app_icon_144x144.png"> <!-- retina iPad iOS 7 --> <link rel="apple-touch-icon" sizes="152x152" href="icons/app_icon_152x152.png"> <link rel="apple-touch-icon" sizes="256x256" href="icons/app_icon_256x256.png"> <link rel="apple-touch-icon" sizes="512x512" href="icons/app_icon_512x512.png"> <link rel="apple-touch-icon" sizes="1024x1024" href="icons/app_icon_1024x1024.png"> <link rel="stylesheet" href="css/stylesheet.css" type="text/css" charset="utf-8" /> <!-- Load Phaser engine --> <script src="lib/phaser.min.js"></script> <!-- Load game source files --> <script src="src/Game.js"></script> <!-- Load game entrance --> <script src="src/app.js"></script> <!-- Load and initialize Cordova --> <script src="cordova.js"></script> <script src="src/cordova-init.js"></script> <script src="src/prefabs/balls.js"></script> <script src="src/prefabs/homes.js"></script> </head> <body> <!-- Main canvas for rendering game stage --> <div id="game"></div> <div id="balls"></div> <div id="homes"></div> </body> </html>

So the problem is I have an error in the prefabs where 'Phaser' is not defined.

在此处输入图片说明

JSHint will report an error because it's only looking at a single file and can't know if some globals were defined elsewhere, as is the case with Phaser . If you look in www/src/app.js you'll see a line like this:

/* globals Phaser:false, BasicGame: false */

This is a JSHint directive that tells it not to flag Phaser or BasicGame as undefined, ie assume they're globals defined elsewhere.

In any case, it shouldn't affect the running of your app. You should see it defined in the debugger and in your running code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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