Jump to content

Function issues


Gritwork
 Share

Recommended Posts

I'm trying to add functions to my game but, when I try to test it, it never goes to the main game room which means there's an error somewhere in there.

var GemMiner = GemMiner || {};//title screenGemMiner.Game = function () {};//game variablesvar player;var block;var cursors;var facing = 'right';GemMiner.Game.prototype = {	create: function(){		//set world dimensions		this.game.physics.startSystem(Phaser.Physics.ARCADE);		this.game.world.setBounds(0, 0, 800, 600);			//add background		this.gamebackground = this.game.add.sprite(0, 0, 'gamebackground');				//add player		this.player = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY + 160, 'player');		this.game.physics.arcade.enable(this.player);		this.player.body.collideWorldBounds = true;		this.player.animations.add('left', [0, 1, 2, 3], 5, true);		this.player.animations.add('right', [5, 6, 7, 8], 5, true);		this.player.animations.add('idle', [4], 20, true);				//player initial score of zero		this.playerScore = 0;			//set up keyboard support to allow player movement		cursors = this.game.input.keyboard.createCursorKeys();				//functions for use		this.generateGems();				//show score		this.showLabels();	},	update: function () {		//player movement			this.player.body.velocity.x = 0;    if (cursors.left.isDown)    {        this.player.body.velocity.x = -150;        if (facing != 'left')        {            this.player.animations.play('left');            facing = 'left';        }    }    else if (cursors.right.isDown)    {        this.player.body.velocity.x = 150;        if (facing != 'right')        {            this.player.animations.play('right');            facing = 'right';        }    }    else    {        if (facing != 'idle')        {            this.player.animations.stop();            if (facing == 'left')            {                this.player.frame = 0;            }            else            {                this.player.frame = 5;            }            facing = 'idle';        }    }			},	//generate the gems that will fall	generateGems: function() {    this.gems = this.game.add.group();    //enable physics in them    this.gems.enableBody = true;    this.game.physics.arcade.enable(this.gems);    //phaser's random number generator    var numCollectables = this.game.rnd.integerInRange(100, 150), gemcollect;    for (var i = 0; i < this.numCollectables; i++) {      //add sprite      this.gemcollect = this.gems.create(this.game.world.randomX, 0, 'gem');    }};

I tried following the phaser tutorials but, I think I might have missed something somewhere. The issue only comes up when I try to have the functions running. If i comment them off the game works just fine.

Link to comment
Share on other sites

As GrindheadGames said intending correctly your code would be easier to see if there is missing brackets etc. At least in this code you can see that you are missing } -bracket from last method.

    //generate the gems that will fall    generateGems: function() {      this.gems = this.game.add.group();      //enable physics in them      this.gems.enableBody = true;      this.game.physics.arcade.enable(this.gems);      //phaser's random number generator      var numCollectables = this.game.rnd.integerInRange(100, 150), gemcollect;      for (var i = 0; i < this.numCollectables; i++) {        //add sprite        this.gemcollect = this.gems.create(this.game.world.randomX, 0, 'gem');      }    } <------------------------ you missing this
Link to comment
Share on other sites

 

As GrindheadGames said intending correctly your code would be easier to see if there is missing brackets etc. At least in this code you can see that you are missing } -bracket from last method.

    //generate the gems that will fall    generateGems: function() {      this.gems = this.game.add.group();      //enable physics in them      this.gems.enableBody = true;      this.game.physics.arcade.enable(this.gems);      //phaser's random number generator      var numCollectables = this.game.rnd.integerInRange(100, 150), gemcollect;      for (var i = 0; i < this.numCollectables; i++) {        //add sprite        this.gemcollect = this.gems.create(this.game.world.randomX, 0, 'gem');      }    } <------------------------ you missing this

Well I added that and still nothing. Also I'm not used to coding so I'm not really sure on how indentation of code is supposed to look honestly. I just throw it up there so i can read it with //comments.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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