Guest User

Untitled

a guest
Oct 7th, 2012
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         update: function() {
  2.  
  3.             // Time to detect IF the user presses a Key, and provide a response.
  4.             if(ig.input.state('UP') && ismove != 2 && ismove != 3 && ismove != 4) {
  5.                 this.vel.y = -this.speed;
  6.                 ismove = 1;
  7.                 this.direction = 1;
  8.                 this.currentAnim = this.anims.UP;
  9.             } else if(ig.input.state('DOWN') && ismove != 1 && ismove != 3 && ismove != 4) {
  10.                 this.vel.y = +this.speed;
  11.                 ismove = 2;
  12.                 this.direction = 2;
  13.                 this.currentAnim = this.anims.DOWN;
  14.             } else if(ig.input.state('LEFT') && ismove != 1 && ismove != 2 && ismove != 4) {
  15.                 this.vel.x = -this.speed;
  16.                 ismove = 3;
  17.                 this.direction = 3;
  18.                 this.currentAnim = this.anims.LEFT;
  19.             } else if(ig.input.state('RIGHT') && ismove != 1 && ismove != 2 && ismove != 3) {
  20.                 this.vel.x = +this.speed;
  21.                 ismove = 4;
  22.                 this.direction = 4;
  23.                 this.currentAnim = this.anims.RIGHT;
  24.             } else {
  25.                 // If no Keys are Pressed, then do nothing but idle.
  26.                 this.vel.x = 0;
  27.                 this.vel.y = 0;
  28.                 ismove = 0;
  29.  
  30.                 // The following lines will cause the player to "remember" the direction in which he was walking, thus it wont return to the starting this.anims.idleDOWN animation.
  31.                 if(this.direction == 1) {this.currentAnim = this.anims.idleUP;}
  32.                 if(this.direction == 2) {this.currentAnim = this.anims.idleDOWN;}
  33.                 if(this.direction == 3) {this.currentAnim = this.anims.idleLEFT;}
  34.                 if(this.direction == 4) {this.currentAnim = this.anims.idleRIGHT;}
  35.             }
  36.  
  37.             this.parent();
  38.         }
Advertisement
Add Comment
Please, Sign In to add comment