Phaser 3 俄罗斯方块克隆体方块无法落地问题排查
Phaser 3俄罗斯方块克隆游戏落地问题
我正在开发一款基于Phaser 3的俄罗斯方块克隆游戏,使用VSCode开发,采用Arcade物理系统,目前遇到方块无法落地的问题:方块会停在用作地面的长透明精灵上方。
初始代码
Create方法
this.active = false; this.activeBlock = null;
Update方法
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.physics.add.collider(this.testblock, this.walls); this.physics.add.collider(this.p1, this.testblock); this.activeBlock = this.testblock; this.active = true; } this.activeBlock.y = this.testblock.y + 0.1; if(Phaser.Input.Keyboard.JustDown(this.keyA) && this.activeBlock.x != 352) { this.activeBlock.x = this.activeBlock.x - 64; } if(Phaser.Input.Keyboard.JustDown(this.keyD) && this.activeBlock.x != 928) { this.activeBlock.x = this.activeBlock.x + 64; } if (this.checkCollision(this.activeBlock, this.ground)){ this.activeBlock = null; this.active = false; }
自定义碰撞检测方法
checkCollision(a, b) { // simple AABB checking if ((a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.height + a.y > b.y) ) { return true; } else { return false; } }
尝试修改后的问题
我尝试修改代码:启用重力并设置为0.1,添加碰撞回调禁用方块物理,但方块仅靠近地面仍未到底,且重力未按设置生效,仍受默认重力影响。

内容的提问来源于stack exchange,提问作者EmptyStone
相关产品推荐
相关产品推荐

