Skip to content

Instantly share code, notes, and snippets.

@eugenioclrc
Last active August 29, 2015 13:57
Show Gist options
  • Save eugenioclrc/9568418 to your computer and use it in GitHub Desktop.
Save eugenioclrc/9568418 to your computer and use it in GitHub Desktop.
phaser gravity posible problem
<html>
<head>
<script src="http://examples.phaser.io/_site/js/phaser.js"></script>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
}
var cursors,_floor,player;
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
player=game.add.sprite(90, 50);
game.physics.enable(player);
_floor=game.add.sprite(90, 200);
game.physics.enable(_floor);
_floor.body.width=600;
_floor.body.heigth=10;
_floor.body.immovable = true;
_floor.body.allowGravity = false;
game.stage.backgroundColor = '#787878';
// if you set the gravity in the create function the player falls really fast
// comment this line and see the example work!
game.physics.arcade.gravity.y = 100;
}
function update() {
game.physics.arcade.gravity.y = 100;
game.physics.arcade.collide(_floor, player);
}
function render() {
game.debug.bodyInfo(player, 32, 320);
game.debug.body(player);
game.debug.body(_floor);
}
</script>
</head>
<body>
<div id="phaser-example"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment