You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 08:10:48