- Creator 版本:v2.0.10
各位大佬, 我用 Cocos Creator 做了一个俄罗斯方块, 在尝试让掉落的方块是匀速下降而不是一格一格的下降的时候, 我发现我没法让小方块在目标位置停下来.
这个是绑定在小方块上的碰撞代码
/**
* 当碰撞产生的时候调用
*/
onCollisionEnter(other, self) {
if (other.node.group != ‘box’){
return;
}else{
this.node.dispatchEvent(new cc.Event.EventCustom(‘foobar’, true));
}
},
然后这是游戏主逻辑上的代码
/**
* 方块匀速下降
/
update:function(dt){
this.yspeed=1;
this.schedule(this.down_seppd, 10dt);
},
/**
* 匀速降落
*
* 问题: 无法精确的暂停
* 当 i = 1 时, 生成新的方块掉落
*/
down_seppd(){
if(this.gamestate === 0){
this.create(); //生成小方块
this.node.y -= this.yspeed;
this.i -= 1;
console.log("--++当前坐标++--"+this.node.y+":-----["+this.i+"]-----");
for(let i=0;i<4;i++){
if(this.box[this.one[i]][this.two[i]] === 1){
this.i++;
this.create(); //生成小方块
}
}
this.check();
}
},
/**
* 全局事件监听
*/
start(){
this.node.on('foobar', function (event) {
console.log("----消息接收成功, 方块停止下降-----");
/**
* 让方块停下来应该是控制它的坐标, 而不是停止调用这个方法
*/
}, this);
},
我希望实现小方块在匀速下降的时候, 跟界面下方发生碰撞检测后就停在原地, 想破头都不知道怎么实现, 求问各位大佬