Jump to content

Getting started with Phaser 2.2.2


spinnerbox
 Share

Recommended Posts

Hello. I today just started with Phaser and I have version 2.2.2 working on my node.js server. The problem I face is, this tutorial is from 2013-th and probably some of the API is deprecated. I keep getting undefined error for this function:

game.physics.startSystem();

I found this post related to the same issue: http://www.html5gamedevs.com/topic/6741-problem-typeerror-gamephysicsstartsystem-is-not-a-function/ and I cannot get enable physics in my first game. 

 

I am noob. What should I do to enable physics in this newer 2.2.2 version of Phaser?

 

The alien falls down to the edge of the canvas and there it bounces, but probably should bounce of the platform and stay there.

 

Here is my code: 

window.onload = function () {    var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create }),        platforms;    function preload () {        game.load.image('logo', 'assets/phaser.png');        game.load.image('sky', 'assets/sky.png');        game.load.image('ground', 'assets/platform.png');        game.load.image('star', 'assets/star.png');        game.load.spritesheet('dude', 'assets/dude.png', 32, 48);    }    function create () {        var ground = null,            ledge = null,            player = null;        //var logo = game.add.sprite(game.world.centerX, game.world.centerY, 'logo');        //logo.anchor.setTo(0.5, 0.5);        //game.add.sprite(0, 0, 'star');        //  We're going to be using physics, so enable the Arcade Physics system        // game.physics.startSystem(Phaser.Physics.ARCADE); -----------------------> this line doesn't work             //  A simple background for our game        game.add.sprite(0, 0, 'sky');             //  The platforms group contains the ground and the 2 ledges we can jump on        platforms = game.add.group();             //  We will enable physics for any object that is created in this group        platforms.enableBody = true;             // Here we create the ground.        ground = platforms.create(0, game.world.height - 64, 'ground');             //  Scale it to fit the width of the game (the original sprite is 400x32 in size)        ground.scale.setTo(2, 2);             //  This stops it from falling away when you jump on it        ground.body.immovable = true;             //  Now let's create two ledges        ledge = platforms.create(400, 400, 'ground');             ledge.body.immovable = true;             ledge = platforms.create(-150, 250, 'ground');             ledge.body.immovable = true;                // The player and its settings        player = game.add.sprite(32, game.world.height - 150, 'dude');             //  We need to enable physics on the player        //game.physics.arcade.enable(player);             //  Player physics properties. Give the little guy a slight bounce.        player.enableBody = true;        player.physicsBodyType = Phaser.Physics.ARCADE;        player.body.bounce.y = 0.2;        player.body.gravity.y = 300;        player.body.collideWorldBounds = true;             //  Our two animations, walking left and right.        player.animations.add('left', [0, 1, 2, 3], 10, true);        player.animations.add('right', [5, 6, 7, 8], 10, true);        player.body.gravity.y = 300;    }    };
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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