How would I remove any object from my array notafications where I.active = false?
Clarification:
I am basically trying to have a certain object in the array “mark itself for deletion” once it performs what it needs to.
I push the parameters to the array with this code:
notafications.push(notafication({
font: "60px pong",
baseline: "top",
align: "left",
color: "#FFFFFF",
text: "this is a test",
x: 100,
y: 100
}));
Then this function does its logical voodoo to it:
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;
}
And finally, here is the notification rendering segment of my 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);
}
});
}
Note:
Yes, I know I have notification spelled wrong in my code. I’ve just continued to spell it wrong on purpose until this portion of the code is done. Then I’ll find-replace it to the correct spelling.
So much for needing help with this. I figured out the solution.
I simply added this bit of code to my gameloop:
Hopefully this will be of use to someone in the future.