Currently in my Tetris clone project, I am focused on working with single blocks and attempting to stack them in rows. Below is the code snippet for handling these blocks:
if (this.active == false){
this.cube = Math.floor((Math.random()* 7));
this.testblock = this.physics.add.sprite(608, 32, this.blocks[this.cube]);
this.testblock.body.immovable = true;
this.testblock.body.allowGravity = false;
//this.testblock.body.setGravityY(-100);
this.physics.add.collider(this.walls, this.testblock);
this.physics.add.collider(this.p1, this.testblock);
this.activeBlock = this.testblock;
this.active = true;
}
this.activeBlock.y = this.activeBlock.y + 0.5;
if(Phaser.Input.Keyboard.JustDown(this.keyE)){
console.log(this.activeBlock.y);
}
// More code follows .......
The game functions properly until the second block lands, at which point it freezes. Upon inspection, an error message displays "Cannot read properties of null (reading 'y')", specifically pointing to the line:
if (this.activeBlock.y == 672)
This line should trigger the landing process for the first row, where a block already occupies that space. It seems like the logic to trigger the landing process for the second row isn't executing.
Even though the block passes the y-coordinate threshold for the second row (608), and there are no apparent instances of setting the active block to null, the issue persists. Can anyone provide insight into what might be causing this unexpected behavior?