How to make item setup like Plants vs Zombies?

Get help using Construct 2

Post » Mon Nov 26, 2012 2:36 am

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!!
-Samavatar862012-11-26 02:37:36
B
10
S
3
Posts: 73
Reputation: 1,431

Post » Mon Nov 26, 2012 7:10 pm

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.

https://www.scirra.com/manual/108/array

Good luck!
B
7
G
1
Posts: 27
Reputation: 991

Post » Mon Nov 26, 2012 11:28 pm

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: http://www.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.Tobye2012-11-26 23:29:18
B
27
S
8
G
5
Posts: 429
Reputation: 6,902

Post » Wed Nov 28, 2012 4:17 am

Oh okayy, I had no idea what an Array is until now lol..
I read this tutorial, http://www.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
B
10
S
3
Posts: 73
Reputation: 1,431

Post » Wed Nov 28, 2012 5:09 am

Hmm, So I made the array, but how do I make this Array visable in my Layout?
B
10
S
3
Posts: 73
Reputation: 1,431


Return to How do I....?

Who is online

Users browsing this forum: Artpunk, OddConfection and 19 guests