I am trying to figure out how to make it so that my game can detect if an object is visible or not to decide if it should be able to do stuff.
I have following actions:
- space: a trajectory line comes up that you can move up and down to set your firing path
- alt: removes this line from the canvas
Up until this point I have just been manually coding in that if the ball lands on the ground/a platform the trajectory line is no longer present because the ball has already been fired. This has lead to many bugs, and I'd much rather just have a function that just constantly checks if there is a trajectory line object present or not to see if the ball can be fired or not.
The below code is just my attempt to test out another stack overflow answer and see if it would work for me. It didn't work, it just returns
"Uncaught TypeError: Cannot read property 'display' of undefined".
I've also seen answers that only work for "jQuery". I tested those and they didn't work. I'm not sure what "jQuery" means, but I'm pretty sure its not the type of JS I'm using.
If it helps, I'm coding this in the JS sandbox on CodeHS. Any help would be appreciated, this is my first project in JS and I'm really unfamiliar with any advanced terms.
var ball;
ball = new Circle(8);
ball.setPosition(8, 292);
ball.setColor(Color.blue);
add(ball);
if (ball.style['display'] != 'none') {
println("visible");
} else {
println("invisible");
}
Edit:This shows the implementation of the Circle class in codeHS https://static.codehs.com/gulp/228d7cf3bdc1b07af7f855a33227666022ce8d4b/jsdoc/chs-js-lib/graphics_circle.js.html