Sign in to follow this  
merak

Enable physics on sprite

Recommended Posts

Im working on simple platformer game and the piece of code below, I cannot activate physics to let walk my player with
game.physics.arcade.enable(player); 
whereever I put this, the error called Cannot read property 'enable' of null or Cannot read property 'arcade' of null appears
What exactly I need do to avoid this problem, thank you.

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', {
  preload: preload,
  create: create,
  update: update },
  false, true, {
    default:'arcade',
    arcade:{
        gravity:{ y: 200}
    }



  });




function preload () {
	
this.game.load.image('stone' , "stone.png");
this.game.load.spritesheet('player', "Player/player_tilesheet.png", 80, 110,);

}

var player;
var controls = {};
var playerSpeed = 250;




function create () {

    this.game.stage.backgroundColor = 0x4888cc;
    this.player = game.add.sprite(360, 480 ,'player');
    this.player.animations.add('walk', [9,10],5,true);
    this.player.animations.play('walk');  
    
     controls = {
    	right: this.input.keyboard.addKey(Phaser.Keyboard.D),
    	left: this.input.keyboard.addKey(Phaser.Keyboard.A)


    };
}



function update () {

	if(controls.right.isDown){

		this.player.animations.play('walk');
		this.player.scale.setTo(1,1);
		this.playerSpeed += playerSpeed;


 if(controls.left.isDown){

    this.player.animations.play('walk');
    this.player.scale.setTo(-1,1);
    this.playerSpeed -= playerSpeed;

  
  }  

  }  

	}
}

 

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.