Jump to content

Phaser: trying to get pixel??


PhasedEvolution
 Share

Recommended Posts

Hello. I am trying to do something similar to this example: http://jsbin.com/wutanilura/edit?js,console,output

This is part of my code: 

 // the way I created the bombs (inside its class). This works fine

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;
            this.bombs_group.bomb.events.onOutOfBounds.add(resetbomb,this.bombs_group.bomb);

}

// the way I created the wall inside its class

 (...)
 this.wall = game.add.sprite(800,100,this.wall_bmd, 0,map_elements_group);
 game.physics.arcade.enable(this.wall);
 this.wall.body.immovable = true;
 this.wall.body.allowGravity = false;


// to fire bombs

 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;
            
        }

// player_bomb is equal to this : *this.bombs_group.bomb
// map_elements
function bombVsMap (player_bomb,map_elements) {
     
        var bomb_x = Math.floor(player_bomb.x);
        var bomb_y = Math.floor(player_bomb.y);

        var get_collision_pixel = wall_bmd.getPixel(bomb_x,bomb_y);
   
        wall_bmd.blendDestinationOut();
        wall_bmd.circle(0, 100, 100, 'rgba(0, 0, 0, 255');
        wall_bmd.blendReset();
        wall_bmd.update(); 

}

The problems I am facing are:

- The bomb_x and bomb_y in the bombVsMap function when console.logged is also "0", but I see the object moving through the map ( Why do I get this value)?

- I can't get the correct pixel when I do wall_bmd.getPixel (even when I put the X and Y position in the parameters the same as the position of the wall_body);

- I can make the wall "dissapear manually" when I set the X and Y of the wall_bmd.circle but the XY referential seems to start on the left upper corner of the bmd? 

Can someone help me please?

Link to comment
Share on other sites

46 minutes ago, samme said:

Make sure the wall bitmap has dimensions identical to the world and the wall sprite is located at (0, 0). That aligns the bitmap coordinates with the world coordinates.

Well, I have it like this. Shouldn't also work?

 this.wall_bmd = game.add.bitmapData(200, 300);
 this.wall_bmd.ctx.beginPath();
 this.wall_bmd.ctx.rect(0, 0, 200, 300);
 this.wall_bmd.ctx.fillStyle = '#FFA07A';
 this.wall_bmd.ctx.fill();

 this.wall = game.add.sprite(800,100,this.wall_bmd, 0,map_elements_group);

 

EDIT : oh got it. I understand what you meant. But this way I have to set my wall body to a rect. How is that? 

EDIT2: I just set the body to a rect. The only problem know is why the bomb position is always 0...

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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