ww3370 Posted February 17, 2014 Share Posted February 17, 2014 Hey folks, I set up a small test scene based on a tutorial here but I am failing to get my player to collide with the platform, and I also am not getting the input to work as I expect to either. I attached the project in case anyone wants to look at it. Here is the code:<!doctype html><html lang="en"><head> <meta charset="UTF-8" /> <title>Test Game</title> <script type="text/javascript" src="phaser.min.js"></script> <style type="text/css"> body { margin: 0; } </style></head><body><script type="text/javascript">var game = new Phaser.Game(480, 320, Phaser.CANVAS, "", {preload: preload, create: create});var ground;var player;var cursors;function preload() { game.load.image('player', 'assets/melon.png'); game.load.image('platform', 'assets/brick2.png');}function create() { ground = game.add.sprite(game.world.width/2, 200, 'platform'); ground.body.immovable = true; player = game.add.sprite(game.world.width/2, 0, 'player'); player.body.bounce.y = 0.4; player.body.gravity.y = 4; player.body.collideWorldBounds = true; cursors = game.input.keyboard.createCursorKeys();}function update() { game.physics.collide(player, ground); if (cursors.up.isDown) { player.body.velocity.y = -350; }}</script></body></html>testgame.zip Link to comment Share on other sites More sharing options...
ww3370 Posted February 18, 2014 Author Share Posted February 18, 2014 I did spot the mistake; I didn't add the update function to the line where I create a new Phaser game object. Link to comment Share on other sites More sharing options...
Recommended Posts