Sign in to follow this  

Enemy kill counter not updating

Recommended Posts

I'm trying to calculate the number of enemies killed but for some reason it is not updating.

I have a monstersKilled = 0 variable in the create section of the GameState.

this.monstersKilled = 0;

I made an enemy prefab where in the damage prototype I want this.monsterKilled to update as enemy's die but it is not updating.

var TowerDefense = TowerDefense || {};

TowerDefense.UnitAI = function (game, x, y, id, health) {, game, x, y, id);
    this.customProps = {
		speed: 100
    // = game;;
    this.scale.x = -1;
    this.body.velocity.x = -100;
    this.checkWorldBounds = true;
    this.body.collideWorldBounds = false;
    this.body.gravity.y = 1400;
    this.customProps.speed = 100; = health;

TowerDefense.UnitAI.prototype = Object.create(Phaser.Sprite.prototype);
TowerDefense.UnitAI.prototype.constructor = TowerDefense.UnitAI;

TowerDefense.UnitAI.prototype.update = function() {
    if (this.customProps.speed) {
		this.body.velocity.x = Math.max(-this.customProps.speed, this.body.velocity.x - 6);
TowerDefense.UnitAI.prototype.reset = function(x, y, id, health){, x, y, health);
TowerDefense.UnitAI.prototype.damage = function(amount) {, amount);
    if( <=0){


here is my create enemy function to reset the enemies as needed

createEnemy: function(x, y, id, health){
     var monster = this.enemyUnits.getFirstExists(false);
         monster = new TowerDefense.UnitAI(, x, y, id, health);
         this.enemyUnits.add(monster);'run', 16, true);
         monster.body.setSize(58,83, 10, 11);
         monster.reset(x, y, id, health);
         monster.animations.add('run');'run', 16, true);
         monster.body.setSize(28,48, 0, 0);


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.