Jump to content

Just getting started and having trouble with collisions and input.


ww3370
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...