1 decade ago by campbellized
Hello everyone, I'm new to Impact and I'm trying to learn the basics of inputs, entities, sprite sheets and all of that good stuff. I've been following along with some tutorials as well as working through Jesse Freeman's book. Well, to get right down to the problem, I've run into a little issue and I'm trying to figure out the cause.
I've mapped out my controls and my basic movements and jump are working fine. However when I try to use my 'attack', I get no response. This is the code for my entity...
The strange thing for me is if I go into the Update function and move the If statement for the Attack below the next If statement, it works (although the animation is jittery).
I'm sure this is some blatantly silly oversight on my part, but I'm really curious why one works and the other doesn't. I've spent hours trying to figure this out! I would be really grateful for any insight that you guys could provide. Thanks!
I've mapped out my controls and my basic movements and jump are working fine. However when I try to use my 'attack', I get no response. This is the code for my entity...
ig.module( 'game.entities.player' ) .requires( 'impact.entity' ) .defines(function(){ EntityPlayer = ig.Entity.extend({ animSheet: new ig.AnimationSheet( 'media/taffy.png', 9, 8 ), size: {x: 9, y:8}, offset: {x: 1, y: 0}, flip: false, maxVel: {x: 75, y: 150}, friction: {x: 600, y: 0}, accelGround: 400, accelAir: 200, jump: 250, init: function( x, y, settings ) { this.parent( x, y, settings ); //Add the animations this.addAnim( 'idle', 1, [0] ); this.addAnim( 'run', 0.09, [0,1,2,3,4,5,6,7,8,9] ); this.addAnim( 'jump', 1, [10] ); this.addAnim( 'fall', 1, [11] ); this.addAnim( 'bat', 10, [12] ); }, update: function() { // move left or right var accel = this.standing ? this.accelGround : this.accelAir; if( ig.input.state('left') ) { this.accel.x = -accel; this.flip = true; }else if( ig.input.state('right') ) { this.accel.x = accel; this.flip = false; }else{ this.accel.x = 0; } // jump if( this.standing && ig.input.pressed('jump') ) { this.vel.y = -this.jump; } // Attack if( this.standing && ig.input.pressed('attack') ) { this.currentAnim = this.anims.bat.rewind(); } // set the current animation, based on the player's speed if( this.vel.y < 0 ) { this.currentAnim = this.anims.jump; }else if( this.vel.y > 0 ) { this.currentAnim = this.anims.fall; }else if( this.vel.x != 0 ) { this.currentAnim = this.anims.run; }else{ this.currentAnim = this.anims.idle; } this.currentAnim.flip.x = this.flip; // move! this.parent(); } }); });
The strange thing for me is if I go into the Update function and move the If statement for the Attack below the next If statement, it works (although the animation is jittery).
if( this.vel.y < 0 ) { this.currentAnim = this.anims.jump; }else if( this.vel.y > 0 ) { this.currentAnim = this.anims.fall; }else if( this.vel.x != 0 ) { this.currentAnim = this.anims.run; }else{ this.currentAnim = this.anims.idle; } // Attack if( this.standing && ig.input.pressed('attack') ) { this.currentAnim = this.anims.bat.rewind(); }
I'm sure this is some blatantly silly oversight on my part, but I'm really curious why one works and the other doesn't. I've spent hours trying to figure this out! I would be really grateful for any insight that you guys could provide. Thanks!