Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by igr

Hi all,
I was replacing getEntitiesByType() with getEntityByName(). It seems to work until my main Hero dies and should be respawned. Then I get an error that the variabel player (var player = ig.game.getEntityByName('hero') is undefined. I understand the logic of the error: the hero is killed but some entities are trying to get hold of it. What I do not understand is why getEntitiesByType() works perfectly here, but getEntityByName() fails?

Another thing is: how to restart the whole level when the main Hero is killed?

Thank you!

1 decade ago by Jesse

once you "kill" an entity, getEntityByName can no longer return it. Is your entity calling "kill" function when it dies?

To restart a level, call ig.game.loadLevelDeferred with the same thing you passed in. Save the level object in a variable like "currentLevel" and just pass that back in when it's time to restart.

You lose the entire state of the level this way though, you might be better off just calling spawn again instead of restarting the entire level.

1 decade ago by igr

Thank you, that is what I thought. But will it mean that I cannot use getEntityByName() on entities which may disappear from the game world?

Thanx for the restart-level help.

1 decade ago by Jesse

"kill" removes it from the world completely

If you want something to disappear, one way to do it is:

when it's time to hide an Entity set its .hidden = true
inside that entity's "draw" function, don't call the parent function if .hidden is true which will make it invisible, but still a solid object that exists in the world.

If you change the entity's update to not call parent, it will stop moving and animating, but is still counted as a solid in the world. So you'll have to set the collides property to NEVER to skip the collision. You can save the values before changing them so you can swap them back when it's time to show again.

1 decade ago by igr

Well the problem that I had was when the main Hero was killed parts of the code was requesting its presence producing error. I had to trick with the health to avoid undifined error.
Page 1 of 1
« first « previous next › last »