How do I Reset global sprites to original position?

0 favourites
  • 9 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • 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?

  • 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.

  • 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.
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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.

  • 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

  • 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.

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