How do I transport my character through layouts?

0 favourites
  • 4 posts
From the Asset Store
Match the color of the black hole with the spaceship as fast as you can!
  • Hi ppl,

    I have a character (sprite) which is my player. When player walks into some "doors" he should be transported to the next layout (level) and be able to back to previous one layout (level).

    Sounds trivial, but... this character (sprite) has several instance values like healthPoints etc. No matter what I try I can't get the instance variables to persist.

    What I have tried:

    1. Add persist behaviour to the object - It doesn't work, but that's understandable cause Persist behaviour remembers the state of the object instance for the particular layout.

    2. Set "playersLayer" to global and player object to global - in result object is automatically (no need to add it manually) created on the layout with the initial state of the instance variables. Well I thought "global" moves the instance to the next layout so I would expect to keep the instance variables unchanged... but not

    3. Allright so I've tried to set layer and character object to global AND add a persist behaviour hoping maybe this will keep the instanca variables set up... but again failure.

    I think I am missing something right? Do I really need to save those values somewhere in a dictionary or so and then load it after layout switch or there is a smart way to move The Player in one piece all over the layouts?

  • I always thought using global on the player-object should keep the instance variables intact..

    Are you sure you are not resetting them through events?

  • Yes I'm sure. I've checked that like ten times. Darn that should be trivial and I stuck with it for a pretty long time now huh.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Awwkay... I got it. My Character is in container with another sprite (his gun), and that gun sprite was not global, that's why I had such a wierd situation.

    I made gun sprite global as well, and it works fine now... duh!

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