How do I remember position of spawned object in next layout

0 favourites
  • 7 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hey there,

    I have a system where you can collect powerups, upon collecting these they will be displayed on the top right corner of the screen.

    As shown here:

    However, when I enter the next layout, all of these powerups are gone.. I gave them a persist behavior.

    Here is a piece of the code:

    As you can see, the position of the powerups is based on how many there are. So basically How do I make the game remember how many powerups there are, which animation frame each one has and the position there have.

  • why dont you just spawn them on start of layout based on the value of 'items' ?

  • You can use "Webstorage" to save collected items on the current layout and then reload them on the next layout that you want to go to.

  • Im not sure how to do that. Im trying something now, making variables for each powerup animation frame.

    with three powerups avaiable it looks like this:

    On collision with s_powerup ->

    s_powerup animation frame = 1 -> add 1 to var.powerup_1

    s_powerup animation frame = 2 -> add 1 to var.powerup_2

    s_powerup animation frame = 3 -> add 1 to var.powerup_3

    So nows the game knows how much of each powerups are collected, but I still don't know how I should make them to be displayed in the next layouts

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well if you make them a global object and have the same layer name in the next frame, theoretically they should persist in to it. Then it's just a matter of recreating them when someone reloads their save games.

    Or you could even make the HUD a global layer and give the objects their own ID values and make them visible based on that.

  • corlenbelspar Wow thanks a lot dude! I didn't even knew global objects existed. It works perfectly now, I just had to make the s_powerup a global object Let's see if I can optimize my game even more now I know this

  • No problem. I would personally do the global layers method because it'd be a bit easier the way I'd do it but I say whatever works best for each project on a case by case basis. Both work either way.

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