Jump to content

Game Freezing


Gritwork
 Share

Recommended Posts

When I set up my game level I can display the top and bottom backgrounds and I can set the player sprite in the image. When I try to enable the physics for the player and collision with the world boundaries however the game will freeze and I can't continue onward. What seems to be the issue with my code?

var SimianScamper = SimianScamper || {};SimianScamper.Game = function(){};SimianScamper.Game.prototype = {	create: function() {			var player;			// SET WORLD DIMENSIONS AND BGCOLOR	this.game.world.setBounds(0, 0, 1920, 965);    this.game.physics.startSystem(Phaser.Physics.ARCADE);	this.game.stage.backgroundColor = '#000';	this.game.physics.arcade.gravity.y = 250;			// ADD CEILING AND FLOOR	this.background = this.game.add.tileSprite(0, 0, this.game.world.width, 64, 'Ceiling');	this.background.autoScroll(-180, 0);		this.background2 = this.game.add.tileSprite(0, this.game.world.height- 64, this.game.world.width, 64, 'Floor');	this.background2.autoScroll(-180, 0);			// ADD PLAYER	this.player = this.game.add.sprite(35, 300, 'Player');	this.game.physics.enable(player, Phaser.Physics.ARCADE);	this.player.body.collideWorldBounds = true;		},	update: function() {			},};

if I comment the game.physics and the player.body lines under the // ADD PLAYER comment the game will run but if I don't it will freeze before loading the screen.

 

 

EDIT:

 

Nevermind I managed to figure it out myself. I needed to change the 

this.game.physics.enable(player, Phaser.Physics.ARCADE);

portion of the code to 

this.game.physics.arcade.enable(this.player);

Simple enough fix really.

 

The only issue I'm having now is the collision with platforms.

var SimianScamper = SimianScamper || {};SimianScamper.Game = function(){};SimianScamper.Game.prototype = {    create: function() {            var player;    var platforms;            // SET WORLD DIMENSIONS AND BGCOLORthis.game.physics.startSystem(Phaser.Physics.ARCADE);    this.game.stage.backgroundColor = '#000';    this.game.world.setBounds(0, 0, 1920, 965);            // ADD CEILING AND FLOOR    this.background = this.game.add.tileSprite(0, 0, this.game.world.width, 64, 'Ceiling');    this.background.autoScroll(-180, 0);    this.background2 = this.game.add.tileSprite(0, this.game.world.height- 64, this.game.world.width, 64, 'Floor');    this.background2.autoScroll(-180, 0);        // COLLISION PLATFORMS    this.platforms = this.game.add.group();    this.platforms.enableBody = true;    var ground = this.platforms.create(0, 901, 'Obstacle');    ground.body.immovable = true;    ground = this.platforms.create(0, 32, 'Obstacle');    ground.body.immovable = true;            // ADD PLAYER    this.player = this.game.add.sprite(35, 300, 'Player');    this.game.physics.arcade.enable(this.player);    this.player.body.gravity.y = 250;    this.player.body.collideWorldBounds = true;        },    update: function() {        // COLLISION OF PLAYER AND BORDERS    this.game.physics.arcade.collide(player, platforms);    },};

And once again I figured it out. For some reason I always seem to after I post a topic. 

 

this.game.physics.arcade.collide(player, platforms);

 

Needed to look like this

 

this.game.physics.arcade.collide(this.player, this.platforms);

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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