Jump to content

Sometimes Alpha doesn't work (possible bug)


Santiago
 Share

Recommended Posts

Hello! I'm still new working with the framework. So, I got a player that for now dies if collides with another sprite or if it falls out the world (sprite !inworld, so kill it and restart), and when it dies, it displays a message and I put a black picture that I set alpha = .7 behind the text. When the player collides with the sprite everything is OK, but when it falls out the world the dark picture shows it without trasparency! 

I also tried loading a picture already with transparency edited with photoshop, so I shouldn't set the alpha property in phaser, but same result! Looks like a bug, but idk, I tried some things but ended in same result! 

here's my Play state:

var play = {

    create: function () {

        this.cursor = game.input.keyboard.createCursorKeys();
        this.jump = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
        this.xKey = game.input.keyboard.addKey(Phaser.Keyboard.X);
        game.world.setBounds(0, -400, 2500, 1000);


        //Fisicas
        game.physics.startSystem(Phaser.Physics.ARCADE);
        game.world.height = 1000;
        //fondo
        game.stage.backgroundColor = "#00FFFF";


        //capa invisible
        //this.fondoInv.alpha = 0;
        
        //codigo de plataformas        

        this.walls = game.add.group();
        this.walls.enableBody = true;


        game.add.sprite(0, 553, 'plataforma', 0, this.walls);
        game.add.sprite(300, 400, 'plataforma', 0, this.walls);
        game.add.sprite(600, 300, 'plataforma', 0, this.walls);
        game.add.sprite(1000, 300, 'plataforma', 0, this.walls);
        
        this.walls.setAll('body.immovable', true); //asi no se caen
        
        
        //plataforma que se cae
        this.wall2 = game.add.sprite(1800, 300, 'plataforma');
        game.physics.arcade.enable(this.wall2);
        
        
        //cosa que mata
        this.asesino = game.add.sprite(1200, 220, 'asesino');
        game.physics.arcade.enable(this.asesino);
        
        this.asesino.body.immovable = true;
        


        //tipo
        this.player = game.add.sprite(125, 500, 'tipito');
        this.player.anchor.setTo(0.5, 1);
        game.camera.follow('tipito');


        game.physics.arcade.enable(this.player);
        this.player.body.gravity.y = 800;
        //this.player.body.collideWorldBounds = true; (PRODUCE BUG CON game.world.setbounds)


        //animaciones    
        this.player.animations.add('correr', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], true);

        
    },



    update: function () {

        //this.walkVelocityR = this.player.body.velocity.x = 200
        //this.walkVelocityL = this.player.body.velocity.x = -200
        //this.jumpVelocity = this.player.body.velocity.y = -400

        game.physics.arcade.collide(this.player, this.walls);
        game.physics.arcade.collide(this.asesino, this.walls);
        game.physics.arcade.collide(this.player, this.wall2);
        game.physics.arcade.overlap(this.player, this.asesino, this.playerDie, null, this)
        

        //this.platforms.body.checkCollision.down = false;
        game.camera.follow(this.player);


        if (!this.player.inWorld) {
            this.playerDie();
        }

        //salto mientras camina

        if ((this.cursor.right.isDown || this.cursor.left.isDown) && this.jump.isDown && this.player.body.wasTouching.down) {
            this.player.body.velocity.x = 380;
            this.player.body.velocity.x = -350;
            this.player.body.velocity.y = -500;
            
        //derecha

        } else if (this.cursor.right.isDown && this.cursor.left.isUp) {
            //this.cursor.left.enabled = false;
            this.player.body.velocity.x = 380;
            this.player.animations.play('correr', 5, true);
            this.player.scale.x = 1;

        //izquierda            

        } else if (this.cursor.left.isDown && this.cursor.right.isUp) {
            //this.cursor.right.enabled = false;
            this.player.body.velocity.x = -380;
            this.player.animations.play('correr', 5, true);
            this.player.scale.x = -1;

                
        }else {
            this.player.body.velocity.x = 0;
            this.player.animations.stop();
            this.player.frame = 4;
        }

        //salto  
            
        if (this.player.body.wasTouching.down) {
            this.jumps = 1;
            console.log(this.jumps)
        }
        
        if (this.jumps > 0 && this.jump.justDown){
            this.player.body.velocity.y = -500
            this.jumps--;
            console.log(this.jumps);
            
        }
        
        
    },

    render: function () {
        //game.debug.inputInfo(32,32);
        game.debug.key(this.cursor.right, 50, 50)
    },

    playerDie: function () {

        this.player.kill();
        
        this.fondoInv = game.add.sprite(game.camera.x, game.camera.y,'fondoInv');
        this.fondoInv.alpha = .77;
        
        var perdiste = game.add.text(game.camera.x + (game.width/2), game.camera.y + (game.height/2), "You have lost", {font: "65px Arial", fill: "#ff0044", align: "center"});
        
        perdiste.anchor.set(0.5,0.5);
        perdiste.fixedtoCamera = true;
        
        
        game.time.events.add(4000, this.start, this)
        

    },

    start: function () {
        
        game.state.start('play');
    }

}

Thanks for helping!

Link to comment
Share on other sites

Are you sure the problem isn't just that playerDie is being called more than once? Probably over and over again. So you're basically adding lots of sprites to the display list.

Stick a console.log inside 'playerDie' and have a look.

Link to comment
Share on other sites

Now testing the game deeper, you're right, it callls it an infinite number of times, idk why the console throw it just once if the player get lost if it "falls" by the sides, but if it falls down the console.log gets looped. Now got to understand why this is happening and got to try to fix it!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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