Best way to handel this

Hey Guys,

On one of the games I am developing I have it set so the player has unlimited lives...if the hero dies on the level he just restarts the level.

One issue I am having is that if the hero kills an enemy on the level, then the hero dies then enemy is gone because of the destroy actor command. I have some Ideas on how to work around this, but are sorts of hacks, and I am sure their is a better and more efficient way.

What would be the most efficient way to do this?

Thanks

Comments

  • ToqueToque Member Posts: 1,188
    edited November 2016

    A bit confusing.

    Can't you just spawn another enemy before destroy. Or just take out the destroy behavior?? Sorry I don't see the question in your post.

    So if unlimited lives you don't want enemy destroyed???

  • JapsterJapster Member Posts: 672
    edited November 2016

    Well, apart from the obvious (Reset Scene) - (You can use GAME attributes to store score, lives, progress), which would work for a static level? - ie. unless you're scrolling along?

    You could do always what I do for re-usable levels - I store my actor names, spawn positions, etc, in a table, and just use a Spawning controller actor, to go through the table, (re)spawning them, on a level restart. (I also have a rule for each spawnable actor, destroying them on a set condition (ie. 'Resetting_Level = true') - if it's game over - I set this to get them to destroy themselves, then after say, a tenth of a second, I reset the flag, and set a 'rebuild_level' flag to get the re-spawner spawning!

    Another way is, instead of spawning and destroying them (and this mainly works well if there aren't a huge amount of actors in your scene) - just move them off-screen instead of destroying them (maybe have them animate as an explosion, disappear / Alpha = 0, etc, or even have a spawned explosion etc appear in their place, then move them off-screen instantly - and just have them 'reset' to their original locations/rotations/size once the 'New Game/Reset Level' user game attribute is set?

    If going the spawning route - just be sure that your actor attributes are consistent, as if you have a scene you've been playing with, the prototype's attributes may well be different from the in-scene instances you've actually manuall moved/placed, so make sure that your Prototype version of those actors have the same 'movable/pin/locked rotation/user attributes' etc settings set, to avoid the basic quirky issues (falling down the screen, being knocked by your main actor, etc... :smiley: ) when you start spawning copies of them from the Proto... :smile:

  • quinn221quinn221 Member Posts: 280

    @Japster said:
    Well, apart from the obvious (Reset Scene) - (You can use GAME attributes to store score, lives, progress), which would work for a static level? - ie. unless you're scrolling along?

    You could do always what I do for re-usable levels - I store my actor names, spawn positions, etc, in a table, and just use a Spawning controller actor, to go through the table, (re)spawning them, on a level restart. (I also have a rule for each spawnable actor, destroying them on a set condition (ie. 'Resetting_Level = true') - if it's game over - I set this to get them to destroy themselves, then after say, a tenth of a second, I reset the flag, and set a 'rebuild_level' flag to get the re-spawner spawning!

    Another way is, instead of spawning and destroying them (and this mainly works well if there aren't a huge amount of actors in your scene) - just move them off-screen instead of destroying them (maybe have them animate as an explosion, disappear / Alpha = 0, etc, or even have a spawned explosion etc appear in their place, then move them off-screen instantly - and just have them 'reset' to their original locations/rotations/size once the 'New Game/Reset Level' user game attribute is set?

    If going the spawning route - just be sure that your actor attributes are consistent, as if you have a scene you've been playing with, the prototype's attributes may well be different from the in-scene instances you've actually manuall moved/placed, so make sure that your Prototype version of those actors have the same 'movable/pin/locked rotation/user attributes' etc settings set, to avoid the basic quirky issues (falling down the screen, being knocked by your main actor, etc... :smiley: ) when you start spawning copies of them from the Proto... :smile:

    Thanks, I did end up just moving them off screen and gave each enemy a self restart x,y and a death x,y.

  • quinn221quinn221 Member Posts: 280

    @Toque said:
    A bit confusing.

    Can't you just spawn another enemy before destroy. Or just take out the destroy behavior?? Sorry I don't see the question in your post.

    So if unlimited lives you don't want enemy destroyed???

    Sorry, I should have given a bit more detail. The game is a platform scroller, each time my hero dies he restarts from the beginning of the level. So lets say my hero is halfway through the level and has killed 5 enemies....then he dies. The hero restarts.... and I want to make sure that the enemies he killed come back to the original place. If I use a destroy, the enemy will not return. I don't want to use a scene reset because I have coins and other objects I don't want to reappear. So I have it set up that the enemies just move offscreen...it works but I was just wondering if their was a better method.

  • ToqueToque Member Posts: 1,188

    Japster method makes sense for that. If they move during play you will have to reset positions then. Remove destroy. Use change positions or change alpha to zero. Follow Japsters post.

  • quinn221quinn221 Member Posts: 280

    Thanks!

    @Toque said:
    Japster method makes sense for that. If they move during play you will have to reset positions then. Remove destroy. Use change positions or change alpha to zero. Follow Japsters post.

  • JapsterJapster Member Posts: 672
    edited November 2016

    Cheers guys - I can't claim that method, I myself picked it up from a guru on here, years ago! :wink:

    PS - if you have lots of rules in these actors, or if they end up having lots of rules, then the destroy/spawner option is probably better to gain performance if you find things are chuggy, unless you add a rule that basically says 'run as long as long as I'm not 'dead' for these actors. There's still a tiny overhead for it to run that one condition, but better than having them all firing off comparisons / rule checking even when off-screen... :wink:

    Of course, there's still the working around of some behaviours/conditions behaving like traps (ie. only firing once) if enclosing in a condition, but many ways to achieve what you need for the above... :smiley: (I believe someone even recently posted a clever comparison expression that always fires.... :wink: )

  • ToqueToque Member Posts: 1,188

    Moving actors on start of scene comes in handy for other things as well. Because in creator we can't turn off layers or actors. They often get in the way. So I place them off scene on the side but the first code is to move to their proper game position. So game starts and they are where you need them but when you go back and change something they are neatly off to the side out of the way so you can quickly access other actors.......

  • SocksSocks London, UK.Member Posts: 12,822

  • ToqueToque Member Posts: 1,188

    @Socks said:

    I've always pictured socks with dark hair...

  • JapsterJapster Member Posts: 672

    @Socks said:

    Ha ha! - like what you did there, @Socks... :wink:

  • SocksSocks London, UK.Member Posts: 12,822

    @Toque said:
    I've always pictured socks with dark hair...

    Under that wig, it's rainbow coloured.

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2016

    @Japster said:
    Ha ha! - like what you did there, @Socks... :wink:

    Definitely my best cheap baroque music joke of the week :p

Sign In or Register to comment.