Jump to content

Why is the .exists method not working?


amanuel
 Share

Recommended Posts

In my update function as you can see it says when Rocket is down whitch is space the current normal doodle exists is false. And yeah it dissapears but the rocket one whitch was previously set to false, now when i hit the keyboard is set to true. But the rocket guy dosent come up on screen when i hit spacebar. Help would be appreciated.

 


 

Code:

 

   


// Initialize Phaser, and create a 400x490px game
    var game = new Phaser.Game(400, 490, Phaser.CANVAS, 'gameDiv');
    
    //Not Needed for this Game
    var CountDown = {
    
        preload: function() {
    
    
        },
        update: function() {
    
        },
        render: function() {
    
    
        }
    }
    //Initalizing Variables i want to check by console
    var player;
    var playerRocket;
    var ground;
    var ledges;
    var mainState = {
    
        preload: function() {
            //Loads the neccecary Images
            game.stage.backgroundColor = '#ccccb3';
            game.load.image('player', 'http://s3.postimg.org/jur41voi7/Doodle.png')
            game.load.image('ground', 'http://s4.postimg.org/c5zfgpjml/platform.png')
            game.load.image('platforms', 'http://s10.postimg.org/evjcsqt9x/sprite_plat.jpg');
            game.load.image('playerLeft', 'http://s24.postimg.org/pc8z7920x/Doodle_Left.png')
             game.load.image('playerRocket', 'http://s7.postimg.org/y6wvfyr6z/145094695410651.gif')
        },
    
        create: function() {
            /*    Arcade Physics. Simple Physics, But there is
                  Ninga Physics and P2 Physics whitch are a 
                  little bit more complicated*/
            game.physics.startSystem(Phaser.Physics.ARCADE);
            //Sets bounds 9999 height so very high
            game.world.setBounds(0, 0, 400, 9999);
    
            //Adds a group
            ledges = game.add.group();
            //Enables phyics on group
            ledges.enableBody = true;
            game.physics.enable(ledges, Phaser.Physics.ARCADE)
                //Creates multiple ledges
            ledges.createMultiple(20, 'platforms');
    
    
            /*MAIN PART OF CODE. Creates MUltiple Platforms at random X but 
            calculated y*/
            for (var i = 0; i < 100000; i += 100) {
                var ledge = ledges.create(Math.floor(Math.random() * 350), 9950 - i, 'platforms');
                ledge.body.immovable = true;
            }
    
    
            //Creates the ground sprite. and adjusts it
            ground = game.add.sprite(0, 9980, 'ground')
            ground.scale.setTo(6, 1)
            ground.enableBody = true;
            game.physics.enable(ground, Phaser.Physics.ARCADE);
            //So it dosent move when player drops on it
            ground.body.immovable = true;
    
            //Player Adjustments
            player = game.add.sprite(100, 9940, 'player');
            player.scale.setTo(0.5);
    
            /*And Phyiscs on player, you can preety much know the
            meaning of all of the words by seeing it...*/
            game.physics.arcade.enable(player);
            player.body.bounce.y = 0.6
            player.body.gravity.y = 500;
            player.body.collideWorldBounds = true;
            // player.body.checkCollision.up = false;
            player.body.checkCollision.left = false;
            player.body.checkCollision.right = false;
            player.body.checkCollision.up = false;
            this.game.inputEnabled = true;
            this.game.input.useHandCursor = true; //FOR SMARTPHONES, TABLETS
           
    
     playerRocket = game.add.sprite(player.body.x, player.body.y, 'playerRocket');
            playerRocket.scale.setTo(0.1);
    
            /*And Phyiscs on player, you can preety much know the
            meaning of all of the words by seeing it...*/
            game.physics.arcade.enable(playerRocket);
            playerRocket.body.bounce.y = 0.6
            playerRocket.body.gravity.y = 500;
            playerRocket.body.collideWorldBounds = true;
            // player.body.checkCollision.up = false;
            playerRocket.body.checkCollision.left = false;
            playerRocket.body.checkCollision.right = false;
    
            playerRocket.body.checkCollision.up = false;
            playerRocket.angle = 15;
            playerRocket.exists = false;
    
             game.camera.follow(player, Phaser.Camera.FOLLOW_PLATFORMER);
            this.cursors = game.input.keyboard.createCursorKeys();
            Rocket = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
        },
    
    
        update: function() {
            //Make sure they collide and not overlap
            game.physics.arcade.collide(player, ground);
            game.physics.arcade.collide(player, ledges);
    
            game.physics.arcade.collide(playerRocket, ground);
            game.physics.arcade.collide(playerRocket, ledges);
    
    
            if (this.cursors.left.isDown) {
                //  Move to the left
                player.body.velocity.x = -150;
                 playerRocket.body.velocity.x = -150;
            } else if (this.cursors.right.isDown) {
                //  Move to the right
                player.body.velocity.x = 150;
                playerRocket.body.velocity.x = 150;
            } else {
                player.body.velocity.x = 0;
                playerRocket.body.velocity.x = 0;
            }
    
    
            if (this.cursors.up.isDown && player.body.touching.down) {
                player.body.velocity.y = -500;
                playerRocket.body.velocity.y = -500;
            }
            if(Rocket.isDown){
                player.exists = false;
                playerRocket.exits = true;
            }
            else{
                player.exists = true;
                playerRocket.exits = false;
            }
    
        },
    
    
    
        // Restart the game
        platformsCreate: function() {
    
        }
    };
    
    var Menu = {
        preload: function() {
            //Loads Images
            game.stage.backgroundColor = '#ccccb3';
            game.load.image('playButton', 'http://s16.postimg.org/70htperg5/playbutton.png')
            game.load.image('backgroundImage', 'http://s1.postimg.org/6t99l4ggf/100309_C10_U1211.jpg')
            game.load.image('doodle', 'http://s7.postimg.org/y6wvfyr6z/145094695410651.gif')
            game.load.image('enemy', 'http://s28.postimg.org/knbclxjq1/145094717130375.gif')
        },
        create: function() {
            //All of the bottom are preety self explanotory
            game.physics.startSystem(Phaser.Physics.ARCADE);
            this.backImage = game.add.sprite(0, 0, 'backgroundImage')
            this.gameText = game.add.text(game.world.centerX, game.world.centerY - 50, "Doodle Jump", {
                font: "60px Times New Roman",
                fill: "#ccccb3",
                fontWeight: "bold",
                stroke: "black",
                strokeThickness: 2.5
            });
            this.gameText.anchor.setTo(0.5)
            this.gameText.angle = -10;
            this.playButton = game.add.sprite(game.world.centerX, 200, 'playButton')
            this.playButton.anchor.setTo(0.5)
            this.playButton.scale.setTo(0.5)
            this.playButton.angle = -10
            game.physics.arcade.enable(this.playButton);
            this.playButton.body.bounce.y = 0.6
            this.playButton.body.gravity.y = 500;
            this.playButton.body.collideWorldBounds = true;
            this.playButton.inputEnabled = true;
            this.playButton.input.useHandCursor = true; //if you want a hand cursor
            this.playButton.events.onInputDown.add(this.start, this);
    
    
            this.doodlePic = game.add.sprite(20, 300, 'doodle')
            this.doodlePic.scale.setTo(0.2)
            game.physics.arcade.enable(this.doodlePic);
            this.doodlePic.body.bounce.y = 0.6
            this.doodlePic.body.gravity.y = 0;
            this.doodlePic.body.collideWorldBounds = true;
    
            this.enemyPic = game.add.sprite(280, 300, 'enemy')
            this.enemyPic.scale.setTo(0.7)
        },
        update: function() {
    
            this.doodlePic.body.velocity.y = -150
        },
        render: function() {
    
        },
        start: function() {
            game.state.start('main')
        }
    
    };
    
    var Game_Over = {
    
        preload: function() {
    
    
    
        },
        create: function() {
    
    
    
    
        },
        update: function() {
    
        },
        render: function() {
    
        },
        onDown: function() {
    
        }
    };
    // Add and start the 'main' state to start the game
    game.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...