How to fill an array with animation frame # after creation?

Get help using Construct 2

Post » Fri Oct 10, 2014 12:33 am

I'm working on a game that is an 8x8 grid of sprites. Each sprite is the same object, just a different animation frame. My goal is to get each row or column of the grid to "slide" on a single axis with a touch gesture according to which sprite is touched and which direction the swipe is. Once a sprite passes through the edge of the grid. It should wrap around to the opposite side, appearing as though each side is connected. When the touch event ends, the sprite should snap to the nearest grid square.

Right now I have the grid set up, the sprites spawn in the correct position with a random animation frame. The sprites slide when swiped and they snap to nearest grid square when the touch event ends. Any sprites left outside the grid (i.e. the "masking" sprites) are destroyed, so there aren't a numerous amount of invisible sprites lingering around.

I'm having a problem with the wrapping portion. I just haven't been able to figure out how to accomplish this. I'm using a 2D array to collect the animation frames of each sprite in the row/column at the time the grid is created and then access the array when a sprite is swiped to set the masking sprites to the proper animation frame. It works great for the first swipe. The masking sprites show up in the right places, everything moves according to the initial axis of the swipe. Everything snaps to the closest grid square. But when you swipe another sprite in the same row/column, the original order of the sprites show up again, instead of the new order. Something like this:

Original order - (masking sprites are regular font and main board sprites are bold)
123456781234567812345678

If the sprites are shifted over by one so the row that was shifted now looks like this -
23456781

But, the masking sprites of the next touch event look like this -
123456782345678112345678

They don't match up. Like I said, I've been trying to use a 2D array to create the masking sprites, so I know I need to shift the index order of the array after every touch event, but I haven't been able to figure out how to do that. Push/pop doesn't do the job and I haven't been able to figure out how to use delete/insert to access the array properly to achieve this.

The only thing I can think of is to use the 2D array to capture the frames at the time of creation, then use a 1D array to store the animation frames at the time of access, then use delete to remove the old values from the 2D array. Push/pop the values of the 1D array to match the amount of squares moved, then insert the contents of the 1D array into the corresponding row/column of the 2D array. :shock: All that just makes me feel like I'm making this way too difficult on myself though. lol

If anyone knows how to help me use an array to do this, or if anyone has any suggestions to use another method I'm willing. lol
B
10
S
1
Posts: 67
Reputation: 909

Post » Fri Oct 10, 2014 2:59 pm

So I tried using a 2D array along with a 1D array. I've got an algorithm for the pop/push according to how many grid squares were moved. That works perfectly, but I'm still not able to put the contents back into the 2D array without the 2D array's contents going haywire.

Am I missing something with the 2D array, or are they made so that we cannot alter a portion of them? From what I remember in college with my c++ and c# classes, arrays (1D and multi-dimensional) can be accessed and altered by index or value, so why aren't we able to do that in Contruct 2?

I'm starting to think I need to make a 1D array for each row and column and figure out how to alter them all together. *so daunting!!!!* :S
B
10
S
1
Posts: 67
Reputation: 909

Post » Fri Oct 10, 2014 4:02 pm

You can do pretty much anything with arrays. But the push/pop thing can be a bit daunting when using more than a dimension. You can't push complete rows, you have to push a single value on the X/Y axis, then modify every cell in subsequent actions, because the value is pushed to all cell of the added row/column.
B
71
S
30
G
25
Posts: 984
Reputation: 19,503

Post » Fri Oct 10, 2014 5:42 pm

@Magistross - So what you're saying is, I can't delete/insert an entire row/column? :( Deep down inside I knew that, but I've been in denial. Lol

Correct me if I'm wrong, but the way I'm understanding what you're saying is I have to push/pop each item (which can only be done from the ends of the array and not at the ends of the rows and columns!!!) in order to adjust the rows and columns? I can't just insert a value at an index, which should move the remaining array down 1, then delete the old index which would move remaining back to their original place?
B
10
S
1
Posts: 67
Reputation: 909

Post » Fri Oct 10, 2014 6:41 pm

No no no, you CAN delete and insert entire row/column. Sorry if I sounded cryptic. It's only that adding and inserting must be done in multiple actions. Deleting a row/column is quite straightforward.

Here's a simple example of a 2D array manipulation.
You do not have the required permissions to view the files attached to this post.
B
71
S
30
G
25
Posts: 984
Reputation: 19,503

Post » Fri Oct 10, 2014 7:02 pm

@Magistross - Thank you for clarifying! I was a little worried. lol

Thanks for the help. I'll see what I can do with this example. :)
B
10
S
1
Posts: 67
Reputation: 909


Return to How do I....?

Who is online

Users browsing this forum: Narus11 and 52 guests