Game Development Reference
In-Depth Information
Figure 14-6. An enemy sprite with health bar
When an enemy attacks, the only thing the Enemy class actually does is create an animation on the enemy sprite
(see Listing 14-11).
Listing 14-11. Enemy.js - The Enemy Sprite Bounces to Indicate it's Attacking
p.playAttackAnimation = function () {
var air = 80;
createjs.Tween.get(this.enemySprite)
.to({y:this.enemySprite.y - air}, 500, createjs.Ease.bounceOut)
.to({y:this.enemySprite.y}, 500, createjs.Ease.bounceOut)
.call(function () {
this.dispatchEvent(events.ENEMY_ATTACK_ANIMATION_COMPLETE);
}, null, this)
}
A simple bounce jump is added to enemySprite . When complete, the ENEMY_ATTACK_ANIMATION_COMPLETE event
is dispatched, which will carry on the attack logic back in the game. When the hero is the one attacking, the enemy
has a lot more responsibility, starting with displaying the target indicator sprite to indicate it to be a valid target
(see Listing 14-12).
 
Search WWH ::




Custom Search