Javascript 从数组中修剪对象,其中";I.active=false";
如何从数组Javascript 从数组中修剪对象,其中";I.active=false";,javascript,arrays,html5-canvas,Javascript,Arrays,Html5 Canvas,如何从数组符号中删除任何对象,其中I.active=false 澄清: 我基本上是试图让数组中的某个对象在执行它需要的操作后“将其自身标记为删除” 我使用以下代码将参数推送到数组: notafications.push(notafication({ font: "60px pong", baseline: "top", align: "left", color: "#FFFFFF", text: "this is a test", x: 100,
符号中删除任何对象,其中I.active=false
澄清:
我基本上是试图让数组中的某个对象在执行它需要的操作后“将其自身标记为删除”
我使用以下代码将参数推送到数组:
notafications.push(notafication({
font: "60px pong",
baseline: "top",
align: "left",
color: "#FFFFFF",
text: "this is a test",
x: 100,
y: 100
}));
然后该函数对其执行逻辑巫术:
function notafication(I) {
I.active = true;
I.render = true;
I.count = 3;
I.flashTimer = setInterval(function() {
if (!pingpong.paused) {
I.count--;
if (I.count%2 == 1) {
I.render = true;
}
else {
I.render = false;
}
if (I.count == 0) {
clearInterval(I.flashTimer);
I.render = false;
I.active = false;
}
}
},750);
return I;
}
最后,这里是我的gameloop的通知呈现部分
if (render.notafication) {
notafications.forEach(function notafication(I) {
ctx.font = I.font;
ctx.textAlign = I.align;
ctx.textBaseline = I.baseline;
ctx.fillStyle = I.color;
if (I.render) {
ctx.fillText(I.text,I.x,I.y);
}
});
}
注意:
是的,我知道我的代码中的通知拼写错误。我只是继续故意拼写错误,直到代码的这一部分完成。然后我会找到正确的拼写来替换它。非常感谢您在这方面的帮助。我想出了解决办法
我只是在gameloop中添加了以下代码:
notafications = notafications.filter(function notafication(I) {
return I.active;
});
希望这对将来的人有用。aauugghhh请现在修改拼写,它正在摧毁我的大脑!