Locked / Unlocked Levels

0 favourites
  • 4 posts
From the Asset Store
Unlock Levels, Worlds & skin plus add coins by watching ads
  • Hi,

    I'm trying to figure out how to create menu with locked / unlocked levels.

    I'm using WebStorage to store and autoload "AvailableLevel" global number.

    Now, where's the catch.

    I'm having 5 sprites (5 levels), and on top of them 4 instances of "locked" sprite.

    I've tried destroying them lock levels by UID, but as I do not know exact UID of object it's a problem.

    I've tried by setting up instance variable, but I cant set

    Instance 1 - have instance variable value = 1

    Instance 2 - have instance variable value = 2


    I've tried by "System pick Lock instance 0,1,2,3,4 - Lock Destroy" and this is closest to working, but for strange reason at one point it destroys 2 locks not only 1 and I do not understand why..

    What's correct approach.

    Idea is to have 22 levels, and I need to know exactly which "locked" sprite instance is which one (by number) in order to create groups and paths.

    Eg. when 1,2,3 are resolved, you get option to play 4 (not 5 and 6), 7 (not 8 and 9) .... like you will have path that you can follow, and then it splits in two and you can choose where to go, what to play.

    I could resolve it by creating 22 times same locked sprite, but I do not find it as "best approach".

    Tnx for any suggestion!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok, as usual when u are fed up and ready to give up, it means you are closest to solution. :)

    I just figured out that I can set value for each instance of lock manually (<varies>), and then easily "Lock value=AvailableLevel: Lock Destroy" ...

    Don't know if this is the best approach but works fine now :)

  • You need a parenting system.

    Basically for your 'lvlSprite' (sprite representing the levels), you create 2 instance variable

    'ID' and 'parentID'

    Then at edit time you set each variable logically.

    • 'ID' can be the number of the level (1-based)
    • 'parentID' should be the ID of the level you have to clear to be able to play this one. 0 for the first level. (this system won't support multiple parent, just simple branching)

    And then you'd just have to know which levels are cleared

    (damn bit masking would make all that so much easier... there's a bit plugin by the way... but the concept might seem a lil bit complicated even if it's not. And also custom plugins aren't arcade-compatible)

    Anyway storing cleared level is the hardest part. I would use a global text with the list of cleared levels

    Global text clearedLVL = ":0:"
    Global number lvlID = 0
    System: On start of layout
      -> lock: destroy
      System: foreach lvlSprite
      System: find(":"&lvlSprite.parentID&":") = -1
        -> lvlSprite: spawn lock

    And when you enter a level

    Mouse: on left click on lvlSprite
    [invert]Mouse: is over lock
      -> set lvlID to lvlSprite.ID
      -> go to layout (by name) "level"&lvlID

    And when you clear a level

    On level cleared
      -> set clearedLVL to clearedLVL&":"&lvlID&":"

    This way you'll build a string of level that will look like


    We have that kind of separation to avoid problem with the find() function.

    That's all

  • Tnx.

    Sound like good way, I'll see if I'll use it.

    I have problems now with lock, [invert]mouse over lock performs action every time and it should not...

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