Spawner: No animationSheet on spawned Entities
Closed this issue · 8 comments
Hi @collinhover,
i think i found a bug, or I misused the SpawnerCharacter
class. I have a spawner that spawns 5 entities over a given time. Regarding to that all works as expected. But if I kill one of the spawned entities, while the spawning is in progress, upcoming entities will be spawned without an animation sheet (they will be invisible). Sometimes the spawner even stops spawning.
Here is a live demo:
You have to move your ship a little bit to the right to trigger the trigger.
This sounds like there is a property on the entities being spawned that is shared amongst all instances of the spawning entity class, and it is getting modified unintentionally. There are two ways I can think of that this can happen:
- you are modifying a prototype property, but you're expecting it to be a property of the instance
- you are modifying the spawnSettings property of the spawner, and it contains properties that each spawned entity needs
I would examine the second option first. Are you using a spawn settings object, and if so does it get modified?
I don't use a spawn settings object. Here is the custom spawner class that I use:
javascript
ig.EntitySpawnerPopcornBall = ig.global.EntitySpawnerPopcornBall = ig.SpawnerCharacter.extend({
delay: 1,
spawningEntity: ig.EntityEnemyPopcornBall,
spawnCountMax: 5,
duration: 6,
spawnAtSide: {
x: 0,
y: -1
},
suicidal: true
});
I am not sure about the first option though, the entity is pretty simple, I just call different `moveTo` methods on that enemy and I don't modify any other properties, except of a small flag variable. But i will examine this further.
Here is a the source of the demo. Would be cool if you could take a look:
https://github.com/Pattentrick/spawner
The relevant files are `game.entities.spawner-popcorn-ball`, `game.entities.enemy-popcorn-ball` and `game.entities.enemy`. The first one is the spawner, the second the enemy and the last one defines all sorts of behavior that is true for all enemies.
By the way, I am not a selfish person and I know that you are very busy at the moment. I am very grateful for your support. I will express my gratitude in my current game. More on that topic later :D
Took a look, the issue has to do with the character's animsExpected
and placeholding animations that are not present. It is a ++ issue, will push a fix shortly for you to test.
This looks like it is going to be a more involved bug hunt, so I'm pushing a temp fix.
FYI, you're using an older version of the library in the demo you posted.
Hey @collinhover,
your temp fix works great! Thanks man! I hope your bug hunt will be successful. I will update to the latest dev version as soon as possible. Also I will finish the game this weekend if I don't run into some bigger unexpected problems. I will send you a link when I am done.
One question though about the spawner class. My entities will travel to a certain point. If that point is reached they will stop moving up, i will set a hasReachedDestination
property to true
and they just move left for the rest of the game. However, if I kill one of those entities who reached their destination, while the spawning is in progress, the next one that will spawn won't move up and starts its movement with a movement to the the left. As if its hasReachedDestination
is also true
.
I think that is related to pooling right? The killed entity returns from the pool and respawns, with all the changes to his properties made in his "old life", right? I tried to define the hasReachedDestination
in the initProperties
. But the init
won't be called again, once the entity returns from its grave.
I fixed that behavior by resetting all important properties at the die
method of the entity and everything works fine. However this feels more like a workaround than a solution. What do you think about this behavior?
You'll want to do the reset in the entity's resetExtras
method.
Alrighty! I close this for now. I can reopen this issue if you want it as reminder for your bug hunt.