Switch between class states within draw()

edited December 2013 in Questions about Code


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++) { 
  activity = 2;

  if (activity == 2) {
  for (int in=0; in<5; in++) {
  activity = 3;

  if (activity == 3) {
  for (int i=0; i<5; i++) {
  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


Sign In or Register to comment.