How do I remember position of spawned object in next layout

Get help using Construct 2

Post » Wed Feb 18, 2015 12:00 am

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:
Image

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:
Image

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.
B
8
S
4
Posts: 120
Reputation: 1,266

Post » Wed Feb 18, 2015 12:30 am

why dont you just spawn them on start of layout based on the value of 'items' ?
B
37
S
11
G
5
Posts: 484
Reputation: 5,313

Post » Wed Feb 18, 2015 12:35 am

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.
Image
B
75
S
16
G
4
Posts: 498
Reputation: 8,778

Post » Wed Feb 18, 2015 3:40 pm

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
B
8
S
4
Posts: 120
Reputation: 1,266

Post » Wed Feb 18, 2015 3:49 pm

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.
B
36
S
8
G
1
Posts: 205
Reputation: 3,213

Post » Wed Feb 18, 2015 6:02 pm

@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
B
8
S
4
Posts: 120
Reputation: 1,266

Post » Wed Feb 18, 2015 10:37 pm

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.
B
36
S
8
G
1
Posts: 205
Reputation: 3,213


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests