collinhover / impactplusplus

Impact++ is a collection of additions to ImpactJS with full featured physics, dynamic lighting, UI, abilities, and more.
http://collinhover.github.com/impactplusplus
MIT License
276 stars 59 forks source link

Spawner: No animationSheet on spawned Entities #153

Closed Pattentrick closed 10 years ago

Pattentrick commented 10 years ago

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:

http://www.shuchu.de/ssr/

You have to move your ship a little bit to the right to trigger the trigger.

collinhover commented 10 years ago

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:

  1. you are modifying a prototype property, but you're expecting it to be a property of the instance
  2. 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?

Pattentrick commented 10 years ago

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
collinhover commented 10 years ago

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.

collinhover commented 10 years ago

This looks like it is going to be a more involved bug hunt, so I'm pushing a temp fix.

collinhover commented 10 years ago

FYI, you're using an older version of the library in the demo you posted.

Pattentrick commented 10 years ago

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?

collinhover commented 10 years ago

You'll want to do the reset in the entity's resetExtras method.

Pattentrick commented 10 years ago

Alrighty! I close this for now. I can reopen this issue if you want it as reminder for your bug hunt.