Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- update: function() {
- // Time to detect IF the user presses a Key, and provide a response.
- if(ig.input.state('UP') && ismove != 2 && ismove != 3 && ismove != 4) {
- this.vel.y = -this.speed;
- ismove = 1;
- this.direction = 1;
- this.currentAnim = this.anims.UP;
- } else if(ig.input.state('DOWN') && ismove != 1 && ismove != 3 && ismove != 4) {
- this.vel.y = +this.speed;
- ismove = 2;
- this.direction = 2;
- this.currentAnim = this.anims.DOWN;
- } else if(ig.input.state('LEFT') && ismove != 1 && ismove != 2 && ismove != 4) {
- this.vel.x = -this.speed;
- ismove = 3;
- this.direction = 3;
- this.currentAnim = this.anims.LEFT;
- } else if(ig.input.state('RIGHT') && ismove != 1 && ismove != 2 && ismove != 3) {
- this.vel.x = +this.speed;
- ismove = 4;
- this.direction = 4;
- this.currentAnim = this.anims.RIGHT;
- } else {
- // If no Keys are Pressed, then do nothing but idle.
- this.vel.x = 0;
- this.vel.y = 0;
- ismove = 0;
- // 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.
- if(this.direction == 1) {this.currentAnim = this.anims.idleUP;}
- if(this.direction == 2) {this.currentAnim = this.anims.idleDOWN;}
- if(this.direction == 3) {this.currentAnim = this.anims.idleLEFT;}
- if(this.direction == 4) {this.currentAnim = this.anims.idleRIGHT;}
- }
- this.parent();
- }
Advertisement
Add Comment
Please, Sign In to add comment