Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

unexpected fallings of blocks


stroma44
 Share

Recommended Posts

I am in a trouble with improper falling blocks. when I click a block, some blocks are killed and, blocks on the air fall. but in some cases some blocks dont stop on the other blocks and continue falling. the important codes and the video about the problem are below.

thanks in advance

 


var blocks = [];  // existing block on the screen

Game.preload = function () {


    loadElements();
};

Game.create = function () {

    ground = game.add.sprite(0, game.world.height - 64  , 'ground');

    game.physics.enable(ground, Phaser.Physics.ARCADE);
    ground.body.immovable = true;
    ground.enableBody = true;

    init_blocks(initial_row, initial_column, 700);


};

Game.update = function () {
    game.physics.arcade.collide(ground, blocks, collision_handler2);
    game.physics.arcade.collide(blocks, blocks, collision_handler);
};

function collision_handler2(ground, block){
    block.body.immovable = true;
}

function collision_handler(block1, block2){
    block1.body.immovable = true;
    block2.body.immovable = true;
}

function killBlocks(blocks) {

    blocks.kill();

    makeMovable();

    createNextBlocks(3);

}

//after killing some blocks, this make fall other blocks which are on the air.
function makeMovable() {
    for (var i = 0; i < blocks.length; i++) {
        blocks[i].body.immovable = false;
        blocks[i].body.velocity.y = 300;
    }
}

function createNextBlocks(num) {

    for (var i = 0; i < num; i++) {
        setTimeout(function timer() {
            // ...
            var block = createBlock(keys[j] * 64, 0, width, height / 2, color, word);
            blocks.push(block);
            j++;
        }, i * 300);

    }
}

function createBlock(x, y, width, height, color, word) {

    var block = game.add.sprite(x, y, color);
    game.physics.arcade.enable(block);
    block.inputEnabled = true;
    block.events.onInputDown.add(blockClick, this);
    block.body.checkCollision=true;

    block.scale.setTo(width, height);
    block.enableBody = true;
    block.body.velocity.y = 500;
    block.color = color;

    addWordToBlock(block, word);

    return block;
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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