We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hey guys i am currently trying to recreate the game bang which is for mobile phone i wanted to give the player a second to get ready so i wrote this code:
long previous;
void setup() {
size(600, 600);
}
void draw() {
previous = millis();
while (millis() - previous <= 1000) {
}
background(0);
previous = millis();
while (millis() - previous <= 1000) {
}
background(255);
}
But when i start the skecth it waits a second background becomes white and does nothing else. What can i do to solve this problem?
Thanks.
Answers
Draw updates the screen only once at the very end of it
So everything that happens before adds up and could disappear
So instead of using while set a boolean playerGetsReady which directs if you show screen A or B (or use a int state which can have 3 or more states
Set this boolean var depending on your timer
see reference for boolean
https://forum.processing.org/two/discussion/8087/what-are-setup-and-draw
https://forum.processing.org/two/discussion/8085/i-display-images-in-sequence-but-i-see-only-the-last-one-why
thanks for your advices guys i have read Chrisir's comment and koogs's links and i finally came up with this code:
i know that its not the best it can be but it works Thanks
i will try to remove the function delay() from my code later
edit post, highlight code, press ctrl-o to format code.
That approach doesn't give you space to work further with the code and make a game
You were closer to a solution before. You should not use delay().
Here there is a boolean, is_white, that tracks if we are in the white state or not. When draw runs, it draws a white background if you are in the white state (when is_white is true). If you are not in the white state (is_white is false), it draws a black background instead.
Then it checks to see if a second has passed since the last time a second had passed. If it has, it remembers when the next time that a second will have passed will be, and toggles the value of is_white. This causes the background to change every second.
OK TfGuy44 i fixed my code and this is what it looks like now:
this is even worse.
with
noLoop
you can't play...Hello again guys i am half way done with this game it has a lot of bugs but i wanted to share this with you
Great progress here!!!
Congrats!!!
Remark:
When you stick with my variable state as an integer and implement new states into it like instructions gameOver rs etc., your draw would be much clearer
Also you might want to make functions to call from draw() so draw becomes leaner
thank you for your suggestions chrisir i will post my finished code here when i finish it
Great !