How to make item setup like Plants vs Zombies?

0 favourites
  • 5 posts
From the Asset Store
Runner Zombie drawing for Zombie Attack Series with nice style and colors.
  • Hey everyone,

    I was wondering if theres a good solid way of creating a item/storage setup like Plants vs Zombies?

    Something like...

    4 slots of empty abilities based on what specific items you flipped on from a list?

    And actually remembering these [slot] values when continuing into the next layout

    I just cant wrap my head around into doing this kind of system

    Any help would be great!!

    Thanks!!

    -Sam

  • Hmm... You're probably looking at dealing with arrays. It's a little more advanced but very useful once you get the hang of it. I'd start with these pages.

    scirra.com/manual/108/array

    Good luck!

  • Whiteheat is right, but really they are very simple for something basic like this. They just seem daunting.

    Array width = 4

    Array height = 2

    Now in an event go to the array > Set at X > X=0, Value = "Slot 1".

    Followed by another action array > Set at X > X=1, Value = "Slot 2". And so on for as many slots as you need.

    Now say you want to drag the items into their spot, give the items in your game drag and drop. Make visible shapes for the slots too and name them accordingly (slot 1, slot 2, etc.).

    Then make 'on click released' or 'on touch released'+ Item is being dragged > Item is overlapping slot > set item position to slot (this will make them snap nicely into place).

    Then when they press okay/start/whatever, go item 1 is overlapping slot 1 > set at XY (in the array)> X="Slot1", Y=Item 1. Do that for each item and slot (there are more efficient ways if you have many items, but for just a handful this will work fine).

    Then finally, when you save the game, save the array too. Simply:

    WebStorage -> Set local key "savedArray" to array.AsJSON

    and to load:

    Array -> Load from JSON string WebStorage.LocalValue("savedArray")

    (Found here: scirra.com/forum/www.scirra.com/forum/copy-an-entire-array_topic53153.html)

    There are a few ways to do it, but if you only have 10 or so items this way is quick and simple. I could give you a few more ideas if this isn't working for you.

  • Oh okayy, I had no idea what an Array is until now lol..

    I read this tutorial, scirra.com/tutorials/307/arrays-for-beginners/page-1

    So I basically need a 2D Array then right?

    I'll let you guys know how it goes.. XD

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hmm, So I made the array, but how do I make this Array visable in my Layout?

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