We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
what's the best way of switching between different class states within void (which acts like a constant loop) with the following example:
I've created a class in which a penguin is created. The different states include walking, jumping(up/down) and more to follow.
Now I want the code to switch between those states after a given parameter is exceeded (like i<20). But my problem is, that the void loop doesn't really want to do, what I'd like it to do.
Here's my current approach to the problem:
void walkback() {
px -= 1;
}
void jumpup() {
px -= 2;
py -= 2;
}
void jumpdown() {
px -= 2;
py += 2;
}
void animate() {
if (activity == 1) {
for (int i=0; i<2; i++) {
walkback();
}
activity = 2;
}
if (activity == 2) {
for (int in=0; in<5; in++) {
jumpup();
println(in);
}
activity = 3;
}
if (activity == 3) {
for (int i=0; i<5; i++) {
jumpdown();
}
activity = 1;
}
}
I want to penguin to walk back a bit, then jump up and afterwards, jump down into the water. My current problem is, is that the penguin stays at the first if (activity == 1) and doesn't move on. The draw loop simply continues to draw it walking back. In the main code's draw, I've entered penguin.animate(); btw.
I hope you guys can help me. If you need more information about the code, shout out.
Best Regards, iSpectra
Answers
That seems similar to this recent post: :-?
http://forum.processing.org/two/discussion/1916/making-a-figure-walk
Ok. I've fixed the problem by myself using switch and case as well as an if in every case, to change the activity variable.