为什么我加了碰撞铅笔检测,调试现实一片空白
来源:4-20 小游戏小鸟碰撞铅笔逻辑实现
![](http://img1.sycdn.imooc.com/user/5458633f0001c2a902200220-100-100.jpg)
南苑扫地僧
2018-03-20
//检测小鸟是否撞击铅笔
static isStrike (bird,pencil) {
let s = false;
if (bird.top>pencil.bottom||bird.bottom<pencil.top||bird.right<pencil.left||bird.left>pencil.right) {
s = true;
return s;
}else {
return !s;
}
}
//检测小鸟是否足撞击地板
check () {
const birds = this.dateStore.get('birds');
const land = this.dateStore.get('land');
const pencils = this.dateStore.get('pencils');
if (birds.birdsY[0] + birds.birdsHeight[0]>=land.y) {
this.isGameover =true;
return;
}
let birdsBorder = {
top:birds.birdsY[0],
bottom:birds.birdsY[0] + birds.birdsHeight[0],
left:birds.birdsX[0],
right:birds.birdsX[0]+birds.birdsWidth[0]
};
let length = pencils.length;
for (let i=0;i<length;i++) {
let pencil = pencils[i];
let pencilBorder = {
top:pencil.y,
bottom:pencil.y + pencil.height,
left:pencil.x,
right:pencil.x + pencil.width
};
if (Director.isStrike(birdsBorder,pencilBorder)) {
this.isGameover = true;
return;
}
}
}
2回答
-
Yzed
2020-02-15
if (bird.top>pencil.bottom||bird.bottom<pencil.top||bird.right<pencil.left||bird.left>pencil.right) { s = true; return s; }else { return !s; }
这里不用分if lese来return 直接 s = true 然后return !s 即可
if里面return s的话 就是游戏一开始直接撞击了 所以直接结束游戏 没有渲染 是空白屏
00 -
傅猿猿
2018-03-21
怎么看好乱,你是加了铅笔碰撞才出现的吗,加了地板碰撞检测有没有出现,console有没有报错,然后完了发个截图 或者源码发我帮你看看
00
相似问题