Created
May 11, 2015 15:47
-
-
Save Shaunakde/281e33f1d9044cf39d53 to your computer and use it in GitHub Desktop.
Basic setup for a Phaser js game - http://jsbin.com/liwero
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Clrfeed-ex01</title> | |
<meta charset="utf-8"> | |
<script src="http://cdn.jsdelivr.net/phaser/2.2.2/phaser.min.js"></script> | |
</head> | |
<body> | |
<div id="game"></div> | |
<script id="jsbin-javascript"> | |
var game = new Phaser.Game(500, 150, Phaser.AUTO, 'game'); | |
var play = function(game){} ; // Constructor | |
play.prototype = { | |
preload:function(){ | |
this.load.baseURL = 'http://files.phaser.io.s3.amazonaws.com/codingtips/issue001/'; | |
this.load.crossOrigin = 'anonymous'; | |
this.load.image('bg', 'assets/background.png'); | |
this.load.image('tank', 'assets/tank.png'); | |
// Note: Graphics from Amiga Tanx Copyright 1991 Gary Roberts | |
game.world.setBounds(0,0,1000,1000); | |
}, | |
create:function(){ | |
this.game.add.sprite(0,0,'bg'); | |
tank = this.game.add.sprite(0,0,'tank'); | |
this.game.camera.follow(tank); | |
}, | |
update:function(){ | |
if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) | |
{ | |
tank.x += 10; | |
} | |
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) | |
{ | |
tank.x -= 10; | |
} | |
} | |
}; | |
game.state.add("L0",play); | |
game.state.start("L0"); | |
</script> | |
<script id="jsbin-source-html" type="text/html"><html> | |
<head> | |
<title>Clrfeed-ex01</title> | |
<meta charset="utf-8"> | |
<script src="//cdn.jsdelivr.net/phaser/2.2.2/phaser.min.js"><\/script> | |
</head> | |
<body> | |
<div id="game"></div> | |
</body> | |
</html></script> | |
<script id="jsbin-source-javascript" type="text/javascript">var game = new Phaser.Game(500, 150, Phaser.AUTO, 'game'); | |
var play = function(game){} ; // Constructor | |
play.prototype = { | |
preload:function(){ | |
this.load.baseURL = 'http://files.phaser.io.s3.amazonaws.com/codingtips/issue001/'; | |
this.load.crossOrigin = 'anonymous'; | |
this.load.image('bg', 'assets/background.png'); | |
this.load.image('tank', 'assets/tank.png'); | |
// Note: Graphics from Amiga Tanx Copyright 1991 Gary Roberts | |
game.world.setBounds(0,0,1000,1000); | |
}, | |
create:function(){ | |
this.game.add.sprite(0,0,'bg'); | |
tank = this.game.add.sprite(0,0,'tank'); | |
this.game.camera.follow(tank); | |
}, | |
update:function(){ | |
if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) | |
{ | |
tank.x += 10; | |
} | |
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) | |
{ | |
tank.x -= 10; | |
} | |
} | |
}; | |
game.state.add("L0",play); | |
game.state.start("L0"); | |
</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var game = new Phaser.Game(500, 150, Phaser.AUTO, 'game'); | |
var play = function(game){} ; // Constructor | |
play.prototype = { | |
preload:function(){ | |
this.load.baseURL = 'http://files.phaser.io.s3.amazonaws.com/codingtips/issue001/'; | |
this.load.crossOrigin = 'anonymous'; | |
this.load.image('bg', 'assets/background.png'); | |
this.load.image('tank', 'assets/tank.png'); | |
// Note: Graphics from Amiga Tanx Copyright 1991 Gary Roberts | |
game.world.setBounds(0,0,1000,1000); | |
}, | |
create:function(){ | |
this.game.add.sprite(0,0,'bg'); | |
tank = this.game.add.sprite(0,0,'tank'); | |
this.game.camera.follow(tank); | |
}, | |
update:function(){ | |
if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) | |
{ | |
tank.x += 10; | |
} | |
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) | |
{ | |
tank.x -= 10; | |
} | |
} | |
}; | |
game.state.add("L0",play); | |
game.state.start("L0"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment