【发布时间】:2021-03-27 15:40:59
【问题描述】:
我有两个布尔变量 var lookingLeft = false、var lookingRight = false 和一个椭圆 ellipse(40, 40, i, i)。
var lookingLeft = false;
var lookingRight = false;
function draw() {
let i = 30;
ellipse(40, 40, i, i);
if (nose.x > leftEye.x) {
lookingLeft = true;
}
if (nose.x > rightEye.x) {
lookingRight = true;
}
if (lookingLeft === true) {
i = i + 10 //this is not working
rect(10, 10, 50, 50); //but this is
}
if (lookingRight === true) {
i = i - 10 //again, this is not working
rect(300, 300, 50, 50); //but this is
}
}
我希望i 增加 10,lookingLeft = true 减少 10,lookingRight = true。
这是我的 p5 网络编辑器草图:https://editor.p5js.org/saskiasmith/sketches/7WMDPGPbrc
非常感谢!
【问题讨论】:
-
i = i + 10或i = i - 10? -
除了左右方向还有别的方向吗?
-
感谢您的回复@VLAZ,但我已经尝试过了,但由于某种原因无法在草图中工作......不太确定我做错了什么
-
那么我们需要在问题中发布minimal reproducible example。
标签: javascript p5.js ml5