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

ig.game.autoSpawnPlayer does not allow setting #101

Closed Mmarzex closed 10 years ago

Mmarzex commented 10 years ago

I am not sure if this is a bug or intended but I want to not have the game auto spawn the player when I load a level, specifically because I have one level with the player and then a level that is the game over screen / title screen. Now in my main class for when I extend GameExtended I set the property autoSpawnPlayer to false but no matter what circumstance, it is always true. Again this could be just me misunderstanding the purpose of that property but I thought I would bring it to your attention. And also loadLevelDeferred(), it does not kill all entities in the previous level, correct?

collinhover commented 10 years ago

I can't seem to reproduce the bug. Just tested:

var game = ig.GameExtended.extend({
    ...
    autoSpawnPlayer: false,
    ...
});

and auto spawn is set to false as expected. You can also set it via the user config, it is controlled by the AUTO_SPAWN_PLAYER property, or in the init method of your game before calling parent. Perhaps you're setting it somewhere else that you forgot about?

loadLevelDeferred kills nothing immediately. It will unload and load a new level on the next update, if that helps. If you want to keep some entities across levels, check out the layer's clearOnLoad property.

Mmarzex commented 10 years ago

I set it just like you do. Would it be reset when I load a new level?

Mmarzex commented 10 years ago

Actually never mind. It was my browser not reloading impact correctly at first.

Mmarzex commented 10 years ago

Alright, now I have more of question based on how loadLevel works. So for example what I am trying to do right now is that I have a level that is the actual game and then a level that is my gameover and titlescreen. Now in the actual game level, I call loadLevelDeferred when the timer hits zero in order to load the gameover screen which works fine. Now on the game over screen I have it that if you press Enter you are suppose to be able to replay the game. Now when I do that, I call loadLevelDeferred to load my main level again and when it loads it is in the same state as it should be before I load the gameover level, meaning my player is killed and the score is whatever it was previous and my timer is at -1 which is when the game over level loads. So is there someway to completely reload a level that all the entities are recreated?

collinhover commented 10 years ago

Sounds like you just need the player to be fully reset? The player is persistent by default, meaning it is never fully released for garbage collection and every time you make a new player it uses the existing one. You can set the player's persistent property to false, or you can clear it manually via the game's clearPersistentEntity method or by replacing the game's persistentEntities property with a new object.