I want to make a program where something appears on the canvas after a certain amount of time. I've used setTimeout() and this is what my code basically looks like:
void drawSomething() {
setTimeout(function() {
/* DRAW SOMETHING */
}, 1500);
}
/* SOME OTHER FUNCTIONS HERE */
void draw() {
drawSomething();
}
However, the
setTimeout()
function only runs once (the first time the
drawSomething()
function is called). What am I doing wrong?
This is my first post on this forum, so I apologise if I'm doing anything wrong.
I've been creating a Copter game recently, but I have a problem. I have a function
drawHelicopter()
which looks like this:
void drawHelicopter() {
// translate bird according to position of mouse cursor
translate(-20, mouseY);
/* helicopter code */
}
A few lines down, I have another function,
drawObstacle(x, y)
:
void drawObstacle(x, y) {
// make sure the obstacle doesn't get translated as well
translate(0, 0);
/* obstacle code */
}
I want the
helicopter
to move depending on the y-coordinate of the mouse cursor, but the obstacles move with the mouse as well, which shouldn't happen since I've written
translate(0, 0);
at the start of the drawObstacle
()
function.
What do I need to do in order to stop the obstacles from moving with the mouse?