Hi, I´m studying in Khan Academy “processing.js” I haven’t seen an specific category for processing.js so I´ll ask here.
Ask a question
Questions Tips & Thanks
Top Recent
I am coding a side scroll game and I have created 2 scenes the first one is the game itself and the second one is just a logo that says: “YOU WIN!!”. Inside the first scene I have put a condition to change the currentScene varible to 2 if you get enough points, later I have put a condition to draw scene 2 if currentScene === 2 but when the condition is reached, the program just stops the draw function but it doesnt draw scene2 Why? I can run this program if I call the drawScene2 inside the draw function but I don´t want to do that because it is not efficient as it was said earlier in the lectures.
Here is the interesting part of the code (I could put all of it if necessary):
currentScene = 1;
var draw = function() {
if (currentScene === 1) {
drawScene1();
}
};
if (currentScene === 2) {
drawScene2();
}
Also I have tried other option that doesn´t work and I dont know why:
currentScene = 1;
if (currentScene === 1) {
var draw = function() {
drawScene1();
};
} else if (currentScene === 2) {
drawScene2();
}
This solution works but I've been told that because scene 2 is static there is no need to have it inside the draw function as it is a waste of energy redrawing it 30 times per second.
currentScene = 1;
draw = function() {
if (currentScene === 1) {
drawScene1();
} else if (currentScene === 2) {
drawScene2();
}
};