How do I Reset global sprites to original position?

Get help using Construct 2

Post » Sun Apr 27, 2014 9:54 pm

I have a game with global sprite coins scattered across a vast and wondrous land. The player picks them up. Poof, they are destroyed and added into the score variable.

Suddenly, the player dies (or beats the game) and wants to replay the game.

Upon replay, the global sprites are gone (remember they were destroyed).

I know how to reset the global variables, but how do you restore/create the global sprites to their original layout position? ...without painstakingly create-object each item in a position. There's hundreds of them!

**Do I have to not destroy them and set position -100,-100, upon replay layout, it will reload position? Any other solution?
B
9
Posts: 18
Reputation: 361

Post » Sun Apr 27, 2014 11:55 pm

Then why destroy them? You could just hide them, set their opacity to 0 and when the player dies just pick them all and restore their opacity to 100.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Mon Apr 28, 2014 10:55 pm

Here are some spontaneous ideas:
- Change the current layout and load again.
- Create a array and store all coint positions. Create the coints again after a reset using the array (for-loop).
- Don't destroy the coints. Just hide them. And show it at restart. Check if visible when add the score.
B
13
S
4
G
1
Posts: 107
Reputation: 1,337

Post » Tue Apr 29, 2014 12:09 am

Thanks guys! I was able to disable collision and opacity to 0 for the coins when colliding with player. The coins are part of a Family, so on restart I put the Family back to collision enabled, and opacity to 100.

This still shows Global items in other layouts when you don't want them there, but luckily I hide the Family and collision when I didn't need them anymore, for a game over or winning layout.

One issue I might have in the future, if you go to a layout that has global items from a previous layout still showing (coins that weren't collected), how do you hide the ones that weren't collected, but still have them show when the player goes back to that layout (so the game remembers coins not collected, and shows them again). I am bypassing this issue right now by making an extremely large layout where global sprites would not share the same X,Y coordinates on different layouts.
B
9
Posts: 18
Reputation: 361

Post » Tue Apr 29, 2014 12:36 am

Perhaps with an instance variable, a Boolean ("Collected") set to false..? The ones that weren't collected and still have the Boolean set to false, could be checked upon start of layout and set hidden/invisible.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Wed Apr 30, 2014 10:43 pm

Thanks eli0s. I've heard of this Boolean from time to time, maybe it's time I sit down and meet Boolean. It sounds like that might work.
B
9
Posts: 18
Reputation: 361

Post » Thu May 01, 2014 12:08 am

A normal variable can also act as a Boolean. For example, If its value is "0" then DON'T do something, if the value is 1 then DO something.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Thu May 01, 2014 2:31 am

I think I know what you mean now. Can you use the Sprite variable to filter between what is collected and what is not collected?

On collision:
Opacity set 0
collision Disable
Sprite Variable = 1

On Reset
Opacity set 100
Collision Enable
Sprite Variable = 0

On 2nd Layout Start:
If Sprite Variable = 0
Opacity Set 0
Collision Disabled

On 1st Layout Start:
If Sprite Variable = 0
Opacity Set 100
Collision Enable
B
9
Posts: 18
Reputation: 361

Post » Thu May 01, 2014 11:50 am

Perhaps somewhere within this mess you can find something useful :)

Since I don't know what method you use to populate the levels with coins and in which way you change levels, I threw a generic solution, most of the logic should stand on most cases though.
You do not have the required permissions to view the files attached to this post.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], wertt22, Yahoo [Bot] and 23 guests