Jump to content

Uncaught TypeError: Cannot read property 'apply' of undefined


amanuel
 Share

Recommended Posts

Uncaught TypeError: Cannot read property 'apply' of undefined?? What is that suppose to mean?

 

Here is my code(Merry Christmass):

 

var game = new Phaser.Game(500, 550, Phaser.CANVAS, 'gameDiv');var CountDown = {    preload: function() {    },    update: function() {    },    render: function() {    }}var player;var bullets;var enemies;var greenEnemiesvar bulletTimer = 0;var mainState = {    preload: function() {        game.load.image('background', 'http://s1.postimg.org/nqynk9tkv/starfield.png')        game.load.image('player', 'http://s28.postimg.org/9qdf4xrfx/145103252914234.gif')        game.load.image('bullet', 'http://s9.postimg.org/z2bptetxn/bullet.png');        game.load.image('green', 'http://s28.postimg.org/kpmq4byt5/enemy_green.png')    },    create: function() {        this.backgroundImg = this.game.add.tileSprite(0, 0, 500, 550, 'background')        player = game.add.sprite(game.world.centerX, 500, 'player')        player.anchor.setTo(0.5)        player.scale.setTo(0.25)        game.physics.arcade.enable(player);        game.physics.enable(player, Phaser.Physics.ARCADE);        player.body.collideWorldBounds = true;        this.game.inputEnabled = true;        this.game.input.useHandCursor = true;        player.body.maxVelocity.setTo(400, 400)        player.body.drag.setTo(400, 400)        //  The baddies!    greenEnemies = game.add.group();    greenEnemies.enableBody = true;    greenEnemies.physicsBodyType = Phaser.Physics.ARCADE;    greenEnemies.createMultiple(5, 'green');    greenEnemies.setAll('anchor.x', 0.5);    greenEnemies.setAll('anchor.y', 0.5);    greenEnemies.setAll('scale.x', 0.5);    greenEnemies.setAll('scale.y', 0.5);    greenEnemies.setAll('angle', 180);    greenEnemies.setAll('outOfBoundsKill', true);    greenEnemies.setAll('checkWorldBounds', true);    this.launchGreenEnemy();        bullets = game.add.group();        bullets.enableBody = true;        bullets.physicsBodyType = Phaser.Physics.ARCADE;        bullets.createMultiple(30, 'bullet');        bullets.setAll('anchor.x', 0.5);        bullets.setAll('anchor.y', 1);        bullets.setAll('outOfBoundsKill', true);        bullets.setAll('checkWorldBounds', true);                    this.cursors = game.input.keyboard.createCursorKeys();        this.fireButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR)    },    update: function() {        this.backgroundImg.tilePosition.y += 2;        player.body.acceleration.x = 0;        if (this.cursors.left.isDown) {            player.body.acceleration.x -= 600;        } else if (this.cursors.right.isDown) {            player.body.acceleration.x += 600;        }        if (this.fireButton.isDown) {            //Grab first bullet from the pool            if (game.time.now > bulletTimer) {                var bullet = bullets.getFirstExists(false);                if (bullet) {                    bullet.reset(player.x, player.y + 8);                    //Getting it up                    bullet.body.velocity.y = -400;                    bulletTimer = game.time.now + 250;                }            }                    }    },    launchGreenEnemy: function(){          var MIN_ENEMY_SPACING = 300;    var MAX_ENEMY_SPACING = 3000;    var ENEMY_SPEED = 300;    var enemy = greenEnemies.getFirstExists(false);    if (enemy) {        enemy.reset(game.rnd.integerInRange(0, game.width), -20);        enemy.body.velocity.x = game.rnd.integerInRange(-300, 300);        enemy.body.velocity.y = ENEMY_SPEED;        enemy.body.drag.x = 100;    }    //  Send another enemy soon    game.time.events.add(game.rnd.integerInRange(300, 3000), this.launchGreenEnemy);    },    // Restart the game    platformsCreate: function() {    }};var Menu = {    preload: function() {    },    create: function() {    },    update: function() {    },    render: function() {    },    start: function() {    }};var Game_Over = {    preload: function() {    },    create: function() {    },    update: function() {    },    render: function() {    },    onDown: function() {    }};// Add and start the 'main' state to start the gamegame.state.add('CountDown', CountDown)game.state.add('main', mainState);game.state.add('Menu', Menu);game.state.add('Game_Over', Game_Over);game.state.start('main');

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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