Jump to content

Phaser not able to destroy bitmap


Recommended Posts

Greetings. I am trying to do something similar to this: http://codepen.io/photonstorm/pen/ogZJPP?editors=001

However I can't destroy the bmd. I don't know why.

// The bmd wall I will generate. I want to "destroy" it when the bombs hit it

this.wall_bmd = game.add.bitmapData(game_width, game_height);
this.wall_bmd.ctx.rect(800, 100, 200, 300);
this.wall_bmd.ctx.fillStyle = '#FFA07A';

this.wall = game.add.sprite(0,0,this.wall_bmd, 0,map_elements_group);
this.wall.body.immovable = true;
this.wall.body.allowGravity = false;
this.wall.body.setSize(200, 300, 800, 100);

// The way I am generating my bombs (I am also having some doughts here...*1)

this.bmd_bomb = game.add.bitmapData(10, 10);
this.bmd_bomb.ctx.rect(0, 0, 10, 10);
this.bmd_bomb.ctx.fillStyle = '#ffffff';

this.bombs_group = game.add.group();
this.bombs_group.enableBody = true;
this.bombs_group.physicsBodyType = Phaser.Physics.ARCADE;

for(var x = 0; x < 20; x++) {

   this.bombs_group.bomb = this.bombs_group.create(0,0,this.bmd_bomb);
   this.bombs_group.bomb.name = 'bomb' + x;
   this.bombs_group.bomb.exists = false;
   this.bombs_group.bomb.visible = false;
   this.bombs_group.bomb.checkWorldBounds = true;


// My firing bomb function 

 function fireBomb(player_bombs,player_body) {

        var bomb = player_bombs.getFirstExists(false);

        if(bomb) {

            bomb.reset(player_body.x + 30,player_body.y + 20);
            bomb.body.velocity.x = 300;


// In the game update function I am doing this (It makes the game REALLY slow) I need a better way to refer to each of the bombs that have been fired...

var bombs = this.player.bombs.bombs_group.children;
         for(var x = 0; x < bombs.length; x++) {
            if(bombs[x].x != 0) {
                var bomb = bombs[x];

// And probably the biggest problem
function bombVsMap (bomb,map_elements) {

        var wall_bmd = map_elements.wall_bmd;

        var bomb_x = Math.floor(bomb.x);
        var bomb_y = Math.floor(bomb.y);
        var get_collision_pixel = wall_bmd.getPixel(bomb_x,bomb_y);
        if(get_collision_pixel.a > 255) {
            wall_bmd.circle(bomb_x, bomb_y, 100, 'rgba(0, 0, 0, 255');


. I am not sure if I can use the overlap or the collision phaser functions to handle the bitmap destruction? Or do I have to do it manually like I did to check for "collision" and if so destroy the map and the bullet.

. If I do have to check for collision manually how can I refer to each of the spawned bullets without making the game really slow?

. Also, I have no idea why the wall is not being destroyed... If I console.log(get_collision_pixel) I see always the "normal pixels".

I am with these problems for a few days already... Can someone please give me an hand?

Thank you a lot :)

Link to comment
Share on other sites

14 horas atrás, lumoludo disse:

Caso this:

if(get_collision_pixel.a > 255) {

Ser Maior do que? Parece Que rápido Você provavelmente vai get_collision_pixel.a Querer <255.

Well actually I am not sure about that. Anyway when I console.log the get_collision_pixel I alway get 0,0,0,0.... I don't even notice any change on the properties...

Link to comment
Share on other sites


  • Recently Browsing   0 members

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