JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/phaser/2.0.6/phaser.min.js"></script>
<a href="#" id="reset">RESET</a>
<div id="phaser-example"></div>
JavaScript
var game;
function generateGame() {
var loadingText;
game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, 'phaser-example', {create: create});
function loadStart() {
console.log('loading');
loadingText.setText("Loading...");
};
function fileComplete(progress, cacheKey, success, totalLoaded, totalFiles) {
console.log('progress: ' + progress + '% (' + totalLoaded + '/' + totalFiles + ')');
loadingText.setText('Loading... ' + progress + '%');
};
function loadComplete() {
var images = ["noImage"];
var group = game.add.group();
var tempSprite;
// Images
for (var i = 0; i < 2; i++) {
tempSprite = group.create(game.world.randomX, game.world.randomY, game.rnd.pick(images));
tempSprite.inputEnabled = true;
tempSprite.input.enableDrag(false, true);
}
console.log('Load complete!');
};
function create() {
// Loader
loadingText = game.add.text(32, 32, '', { fill: '#666666' });
game.load.onLoadStart.add(loadStart, this);
game.load.onFileComplete.add(fileComplete, this);
game.load.onLoadComplete.add(loadComplete, this);
start();
};
function start() {
// Loading resources
//game.load.image('background2', 'img/land.jpeg');
game.load.start();
};
}
$("#reset").click(function(){
if (typeof game !== "undefined") {
game.destroy();
$("#phaser-example").html('');
}
console.log(game);
generateGame();
});