1 decade ago by janix2011
Let me just start off by saying thank you to Dominic for this amazing framework. Without Impact I would still be messing around with rpg makers and whatnot.
So, I have started working on a game for a college class assignment. Everything is going pretty well for the most part, but I have stumbled upon a problem that I just can't seem to fix myself. I am trying to get my player's attack projectile (sword) to flip according to the facing of my character. I have the sword entity traveling in the correct directions, but the sprite doesn't flip to aim in the right direction.
I have looked at every forum thread pertaining to flipping animations, and nothing there has fixed the problem. I did find the (this.currentAnim.flip.x = true) statement, which seems to flip the sword like I need. Problem is I am still new to the workings of basing things off of the parent entity. Anyone mind helping me with the structure of how to flip the animation if the character is facing left?
Here is the player entity which includes the sword:
So, I have started working on a game for a college class assignment. Everything is going pretty well for the most part, but I have stumbled upon a problem that I just can't seem to fix myself. I am trying to get my player's attack projectile (sword) to flip according to the facing of my character. I have the sword entity traveling in the correct directions, but the sprite doesn't flip to aim in the right direction.
I have looked at every forum thread pertaining to flipping animations, and nothing there has fixed the problem. I did find the (this.currentAnim.flip.x = true) statement, which seems to flip the sword like I need. Problem is I am still new to the workings of basing things off of the parent entity. Anyone mind helping me with the structure of how to flip the animation if the character is facing left?
Here is the player entity which includes the sword:
ig.module( 'game.entities.player' ) .requires ( 'impact.entity' ) .defines(function() { EntityPlayer = ig.Entity.extend({ size: {x:16, y:32}, maxVel: {x: 100, y: 220}, health: 100, flip: true, friction: {x: 0, y: 0}, accelGround: 400, accelAir: 400, jump: 220, invincible: true, invincibleDelay: 2, invincibleTimer: null, type: ig.Entity.TYPE.A, checkAgainst: ig.Entity.TYPE.NONE, collides: ig.Entity.COLLIDES.PASSIVE, animSheet: new ig.AnimationSheet('media/wink2.png',16,32), init: function(x,y,settings){ this.parent(x,y,settings); this.addAnim('idle',1,[0]); this.addAnim('run',0.25,[0,1]); this.addAnim('jump',1,[0]); this.invincibleTimer = new ig.Timer(); this.makeInvincible(); /* if( !ig.global.wm ) { ig.game.spawnEntity(EntityHealthBar,this.pos.x , this.pos.y,{ Unit: this }); } */ }, makeInvincible: function(){ this.invincible = true; this.invincibleTimer.reset(); }, receiveDamage: function(amount, from){ if(this.invincible) return; this.parent(amount, from); }, draw: function(){ if(this.invincible) this.currentAnim.alpha = this.invincibleTimer.delta()/this.invincibleDelay * 1 ; this.parent(); }, update: function() { var accel = this.standing ? this.accelGround : this.accelAir; if( this.standing && ig.input.pressed('jump') ) { this.vel.y = -this.jump; } if(ig.input.state('left')) { this.vel.x = -80; this.flip = true; } else if(ig.input.state('right')) { this.vel.x = 80; this.flip = false; } else { this.vel.x = 0; } if( this.vel.x != 0 ) { this.currentAnim = this.anims.run; } else { this.currentAnim = this.anims.idle; }; if(ig.input.pressed('throw')) { ig.game.spawnEntity( EntitySword, this.pos.x, this.pos.y, {flip:this.flip}); } this.currentAnim.flip.x = this.flip; this.parent(); if( this.invincibleTimer.delta() > this.invincibleDelay ) { this.invincible = false; this.currentAnim.alpha = 1; } }, }); EntitySword = ig.Entity.extend({ size: {x:16, y:16}, animSheet: new ig.AnimationSheet('media/sword.png',16 ,16), maxVel: {x:150, y:0 }, type: ig.Entity.TYPE.NONE, checkAgainst: ig.Entity.TYPE.B, collides: ig.Entity.COLLIDES.PASSIVE, check: function(other) { other.receiveDamage(10, this ); this.kill(); }, init: function( x, y, settings ) { this.parent( x + (settings.flip ? -4 : 8) , y+8, settings ); this.vel.x = this.accel.x = (settings.flip ? -this.maxVel.x : this.maxVel.x); this.addAnim( 'idle', 0.2, [0] ); //This flips the sword sprite, but then it will always face left even if traveling right. this.currentAnim.flip.x = true; }, handleMovementTrace: function( res ) { this.parent(res); if(res.collision.x || res.collision.y) { this.kill(); } } }); });