[SOLVED]Actor Spawning Issue

Talk about making games.

[SOLVED]Actor Spawning Issue

Postby DragonRift » Wed May 15, 2013 9:42 pm

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;
}
Last edited by DragonRift on Wed May 15, 2013 10:39 pm, edited 1 time in total.
DragonRift
 
Posts: 70
Joined: Mon May 13, 2013 5:05 am
Score: 0 Give a positive score

Re: Actor Spawning Issue

Postby skydereign » Wed May 15, 2013 10:12 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Actor Spawning Issue

Postby DragonRift » Wed May 15, 2013 10:18 pm

Issue is resolved, thank you.
DragonRift
 
Posts: 70
Joined: Mon May 13, 2013 5:05 am
Score: 0 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest