How do I avoid problems restarting Layout

0 favourites
  • 4 posts
From the Asset Store
Plugin Transition Layout C3. Layout opening and closing animation for C3. Quickly set up transitions between lay
  • Hello.

    I have problems with the instance variables, and the behaviour-functions not working as expected after restarting a Layout.

    Before I get into the depth explaining my problems I gladly accept all suggestion of 'what to think of when restarting a Layout.' If you like me have built a Level in a game that needs get restarted for the player to start from it's original starting point.


    What I have done is that I have made a Level on a layout. If the player gets killed he needs to start over from his original starting point. The reason I need to restart the layout is that I have made a kind of system, a kind of editor in Construct, where I've placed different objects (Sprites) on the layout to build the level. The sprites (lets call them spawning-sprites) spawn different things, like... Enemies, and Towers. The spawning-sprites gives different properties to the Enemies and so on. To do so the spawning-sprites uses it's instance variables and sets the thing that gets spawned - it's own instance-variables.

    I hope you follow me so far.

    To sum up. I've made a level on the Layout, placing out all the stuff and mobs - setting their properties.

    To explain more about the mechanics...

    When a spawning-sprite Is On Screen, they spawn for example an Enemy. Sets their amount of Ammo, their bulletspeed, the attackspeed, range, points, their state, what animation to use, and so on. All this comes from instance variables from the spawning-sprite.

    Some things sets the Enemy's own instance variables, and other things that are set are different behaviour properties, like Range for the LOS behaviour.

    Its HERE i get problems.

    The reason I've done this is that By placing a spawning-sprite. I can trigger a function that spawn an entire wave of enemies, making them move in patterns and so on. The enemies uses the spawning-sprite for different things. For example uses it's image-points to move in different patterns. I've also made a figure (picture) showing the way the enemy should move. This way I've made a kind of pool, with spawning-sprites that makes the enemy do different things. I can then Place them in a nice way in Construct building up my level. And the benefits are that I can see in Construct roughly how the level should look like and this way I can use the Layouts to make different levels, using the same components, just setting them up differently.

    If I preview the game from Construct. Everything runs perfectly. The player spawns at the right place, the screen moves to the player. All stuff at the map spawns, and they have the right properties and do the right things.

    However, if I get killed, and are supposed to start from the beginning. ( I restart the layout.) The stuff on the map does not perform as they are meant to.

    When I run the game in Debug-Layout-mode I try to find the problems. But all the instance-variables for the different objects seems fine. I cant find the problem.

    For example. If an Enemy has more than 0 ammo ( ammo > 0 ). The enemy are in range to the player, enemy has Line Of Sight. And finally are the right "Type" they should fire at the Player.

    They do not do so? Even though when I check the variables, and other properties for the enemy at the debug-layout. And all things are set correctly.

    I have not used a single global or local variable in the game.

    I also, the global property you can set for Sprites. They are not set to "global", except for one. That only one are the Score-Sprite, with 2 instance variables: Score and Lifes.

    In the Construct manual. it says:

    [quote:2fn4j75h]Restart layout

    Restart the current layout. Note that unlike Go to layout, this action resets all event groups to their initial activation state. Global variables keep their current value - they are not reset. To reset them use the system action Reset global variables.

    I'm not sure how to interpret this. If it means all variables, instance or not, get reset unless they are Global?

    Right now, it feels like it's something with the LOS-behaviour. It feels like even though the enemy are in range, the LOS cant sense it? It could be the cone-of-view or the range. I dont know.

    I'm working on placing some sprites as indicators, to see visually how far the range are, and how the cone of view are set.

    Enough of explaining.

    Anyhow, I appreciate any input you can have about what you think could solve this problem.



  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I've solved some of the problems.

    It helped alot by having "Destroy Player" at the start of the layout. And then creating the Player again.

    I have the player Outside layout, and has the behaviour "Destroy outside layout". but for some reason when I restart the layout I get 2 player objects? :/ And the enemies are targeting the one outside of the layout

    Perhaps if I run into more problems, I could try destroy all objects that are affected at start of layout, and then create them again.

  • Soulmachine I have had this very same issue. Thought it was just something I was doing and not a bug. Thanks I will try that fix as well.

    So you are doing on start of layout-> destroy player

    then having another object ->spawn player

    Is that correct?

  • That is correct.

    ...That's pretty much what I did.

    But instead I have it in a Function called "Initialize" And that function is the first thing (the first Action) in the Start of layout.

    "On start of layout" - Function | Call "Initialize"

    and in the function On "Initialize" I have - Player | Destroy

    Directly after I then have Create | Player ( or I have an Object on the layout called SpawnPlayer that then spawns the player )

    If you simply put Player | Destroy in start of layout it should do the same I think. Instead having it in a INIT-function like I have.

    At least that fixed my problem.

    The problem I had was that all my towers, and also normal enemies that use the Tower and/or LineOfSight behaviour, targeted the Player object OUTSIDE the layout.

    And after the Destroy Player fix, my game have worked fine.

    I recommend all people, if you plan to use restart layout in your project - to test often what happen when you restart.. after you did some work, cause unexpected things could happen.

    I'm glad I could help.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)