merak Posted June 4, 2019 Share Posted June 4, 2019 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; } } } } Link to comment Share on other sites More sharing options...
Recommended Posts