Jump to content

Hit effect


AlexArroyoDuque
 Share

Recommended Posts

One of the first things I did after discovering Phaser, was the edit some of the existing tutorials to try and add more functionality. I did a basic hit effect as part of this. It's a bit chaotic and and could be better (not very well done) but its something I swiftly through together to see what Phaser could do with regards to a standard platforming game. I hope this helps. Please note this was done using 1.1.3 however.

 

// Shows the player sprite being knocked away from the enemy after taking a hit (being touched)function knockedBackAnimation() {	player.animations.stop(); 		// Initialize knock back	var distance = 75;		if(knockedTo == 0)	{		immortal				= true;		knockedDirection		= knockedbackDirection(player, monster);				switch(knockedDirection)		{			case 'left':				knockedTo		= (player.body.x - distance);			break;			case 'right':				knockedTo		= (player.body.x + distance);			break;		}			}		switch(knockedDirection)	{		case 'left':			player.frame 	= 11;			knockedVelocityX= -500;						// Parabolic knock back arc			player.body.velocity.x = knockedVelocityX;						if(player.body.x <= (knockedTo + distance/2))			{				player.body.velocity.y = 100;			}			else			{				player.body.velocity.y = -100;			}						// Player has been knocked back as far as he needs to, reset			if(player.body.x <= knockedTo || player.bottomLeft.x <= 0)			{				player.frame 	= 6;				facing 			= 'right';				knockedTo 		= 0;				knockback 		= false;			}					break;				case 'right':			player.frame 	= 1;			knockedVelocityX= 500;						// Parabolic knock back arc - A major pain in my ass			player.body.velocity.x = knockedVelocityX;						if(player.body.x >= (knockedTo + distance/2))			{				player.body.velocity.y = 100;			}			else			{				player.body.velocity.y = -100;			}						// Player has been knocked back as far as he needs to, reset			if(player.body.x >= knockedTo || player.bottomRight.x >= game.canvas.width + 30)			{				player.frame 	= 12;				facing 			= 'left';				knockedTo 		= 0;				knockback 		= false;			}					break;	}		// A ghostly visage for a short stint of immortality	player.body.sprite.alpha = 0.5;}
Link to comment
Share on other sites

  • 1 month later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...