1 decade ago by KenD
I'm using inheritance and composition to make managing my various non-player entities easier to manage. I've got base Enemy and Friendly classes, and a separate Death class. In the Enemy/Friendly class, I've overridden kill() to spawn an instance of Death, passing in enough settings so it should be able to create its animation sheet and be sized and positioned correctly. The Enemy and Friendly classes are subclassed to create the actual entities. Those classes basically just assign animation sheets and animations, and those are working just fine. When I kill an entity and check the console, it looks like everything's working, but I don't see the animation on screen.
Here's the overridden kill method:
Here's my Death class (contained in its own .js file so both Friendly and Enemy can access it):
There are no errors, and the positions line up with the spawned entity, but nothing is displayed. The Death's off-screen check works, so Impact is definitely spawning the entity. I tried hard-coding an animation sheet in the Death class, but still nothing. What could be preventing my animation from showing like that?
Here's the overridden kill method:
kill: function() { var settings = { size: this.size, offset: this.offset, animSheet: this.animSheet, animSheetFrameArray: this.deathFrames }; ig.game.spawnEntity(EntityDeath, this.pos.x, this.pos.y, settings); this.parent(); }
Here's my Death class (contained in its own .js file so both Friendly and Enemy can access it):
EntityDeath = ig.Entity.extend({ type: ig.Entity.TYPE.NONE, collides: ig.Entity.COLLIDES.NEVER, gravityFactor: 0, init: function (x, y, settings) { this.parent(x, y, settings); this.addAnim('die', 0.07, settings.animSheetFrameArray, true); console.log("Death spawned!", x, y, settings); console.log(this); }, update: function() { // Kill the animation once it scrolls off screen if (this.pos.x < ig.game.screen.x) { console.log("Killing death animation."); console.log(this); this.kill(); } this.parent(); } });
There are no errors, and the positions line up with the spawned entity, but nothing is displayed. The Death's off-screen check works, so Impact is definitely spawning the entity. I tried hard-coding an animation sheet in the Death class, but still nothing. What could be preventing my animation from showing like that?