Geaz Posted February 22, 2014 Share Posted February 22, 2014 Hi all, I implemented a test with phaser in which i got a 6 columns x 6 rows big field full of blocks.In the beginning of the "game" the blocks get generated and fall from above onto an immovable sprite. Everything works as expected.Now, if I remove some of the blocks (kill) the remaining blocks should fall down and new generated blocks should fall on top of the remaining ones.Here I hit a problem:In the moment the new blocks fall from above they seem to "push" the remaining ones through each other. I hope you understand my problem. Here is the relevant code I used:create() { this.game.stage.backgroundColor = "#000000"; this.border = this.game.add.sprite(0, 896, 'border'); this.border.body.immovable = true; // Here I create the column groups for (var i = 0; i < 6; i++) { var group = this.game.add.group(); group.createMultiple(6, 'motdAssets'); this.columns.push(group); }}update() { for (var i = 0; i < 6; i++) { this.currentColumn = i; this.columns[i].forEachDead(this.createRandomBlock, this); // create new blocks if "old" ones get killed this.columns[i].forEachAlive(this.worldBlockCollitionTest, this); // check collision with the bottom border this.game.physics.collide(this.columns[i], this.columns[i]); // all items from one column should collide with each other } }private createRandomBlock(block: Phaser.Sprite): void { var spriteName = this.getRandomSpriteName(); block.reset(this.currentColumn * 128, this.columns[this.currentColumn].countLiving() * - 130); block.frameName = spriteName; block.body.gravity.y = 500;}private worldBlockCollitionTest(block: Phaser.Sprite) { this.game.physics.collide(block, this.border);}I hope you are able to help me Thanks in advanceGeaz Link to comment Share on other sites More sharing options...
Geaz Posted February 23, 2014 Author Share Posted February 23, 2014 Ok, this seems to be a bug with the gravity. It happens, that the internal "block" check fails and applies gravity to elements which are actual blocked. That causes glitches with stacked objects. EDIT: If I dont reuse the objects in the groups (kill and reset), but destroy and recreate them, it seems to work. Link to comment Share on other sites More sharing options...
Recommended Posts