JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://dl.dropboxusercontent.com/s/nprvawkml8mav45/phaser.min.js"></script>
<div id="game_div"> </div>
CSS
#game_div {
width: 400px;
margin: auto;
margin-top: 50px;
}
JavaScript
var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div');
var game_state = {};
game_state.main = function() { };
game_state.main.prototype = {
preload: function() {
//Load sprites
game.load.image('shop','http://i.imgur.com/mfYj52r.png');
game.load.spritesheet('btnexit','http://i.imgur.com/anlNv1n.png',100,35);
},
create: function() {
//Show message
message = game.add.text(10,10,"Press E to open shop");
message.fill = "#E09F1D";
},
update: function() {
//Open shop when 'E' is pressed
if (game.input.keyboard.isDown(Phaser.Keyboard.E)){
openShop();
}
},
openShop: function() {
//Display shop UI and button
shop = game.add.sprite(0,0,'shop');
btnExit = game.add.button(0,0,'btnexit',closeShop,this,2,1,0);
},
closeShop: function () {
//Remove shop items
shop.destroy();
btnExit.destroy();
},
};
game.state.add('main', game_state.main);
game.state.start('main');