Page 1 of 1

[SOLVED]Actor Spawning Issue

PostPosted: Wed May 15, 2013 9:42 pm
by DragonRift
Hello, I am trying to add thruster graphics to my player however it keeps spawning the actor every cycle, and no matter what I do... I cannot seem to fix it.

Here is the code:

Code: Select all
char *key=GetKeyState();
int dir=key[KEY_RIGHT]-key[KEY_LEFT];
int fly=key[KEY_UP]-key[KEY_DOWN];
int ThrustLeft=0;

switch(dir)
  {
  case 0: //None or Both
        ChangeAnimation("Hover", "magneto_hover5x1_normal", NO_CHANGE);
        ThrustLeft=0;
  break;
 
  case -1: //Left
        x-=5;
        view.x-=5;
        ChangeAnimation("Ship", "Concord_Left", NO_CHANGE);
        if (ThrustLeft==0)
        {
          ThrustLeft=1;
          CreateActor("Thrust_Left", "magneto_thruster1x5_magenta_thi", "Player", "(none)", 65, 16, false);
        }

        break;
 
  case 1: //Right
        x+=5;
        view.x+=5;
        ChangeAnimation("Ship", "Concord_Right", NO_CHANGE);
        //Create Thruster Anim Here
  break;
}


switch(fly)
  {
  case 0: //None or Both
        ChangeAnimation("Hover", "magneto_hover5x1_normal", NO_CHANGE);
  break;
 
  case -1: //Down
        y+=3;
        view.y+=3;
        ChangeAnimation("Hover", "magneto_hover5x1_weak", NO_CHANGE);
        break;
 
  case 1: //Up
        y-=2;
        view.y-=2;
        ChangeAnimation("Hover", "magneto_hover5x1_strong", NO_CHANGE);
  break;
}

Re: Actor Spawning Issue

PostPosted: Wed May 15, 2013 10:12 pm
by skydereign
That is because you are creating a local copy of the ThrustLeft variable, and each time setting it to 0. That means every time it gets to the if statement that checks for ThrustLeft, it will always be 0, and therefore always create the actor.

Re: Actor Spawning Issue

PostPosted: Wed May 15, 2013 10:18 pm
by DragonRift
Issue is resolved, thank you.