How do I create a grid-based interface using arrays?

Get help using Construct 2

Post » Wed Apr 09, 2014 5:39 pm

I'd like to create a grid-based game so that the structure looks like this:
grid2.jpg

So say you have columns labeled as A-D and rows labeled as 1-4. And the user selects something in A3 which gets destroyed. I want to be able to replace the object in A3 now with some other object. Would I do this using an array? Is this considered a 2D array or something else?

Thanks for any help you can provide on this.
You do not have the required permissions to view the files attached to this post.
B
7
S
1
G
1
Posts: 56
Reputation: 732

Post » Wed Apr 09, 2014 7:01 pm

You don't necessarily need the array, you can create the grid with a loop and store the (x,y) index of each tile as instance variables. I made the grid quickly for you as an example.
https://dl.dropboxusercontent.com/u/139 ... 4grid.capx
B
11
S
2
G
1
Posts: 202
Reputation: 1,580

Post » Wed Apr 09, 2014 7:11 pm

Imagine that each white square of your grid was an object. And it was stored ina 2d array.. A3 would be index (0,2), just replace the object in there
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Wed Apr 09, 2014 8:11 pm

Thanks for the capx, @Noncentz705. On a slightly unrelated note, I have yet to update my v163 of C2--do you recommend just downloading the latest full version (v165?) and replacing my current version? Is there an update option that I don't see in C2?

Thanks also @caiorosisca, I'll start reading up more on 2D arrays as well.
B
7
S
1
G
1
Posts: 56
Reputation: 732


Return to How do I....?

Who is online

Users browsing this forum: Importuno and 7 guests