Sprite shuffling like on IOS home screen

Get help using Construct 2

Post » Wed Sep 25, 2013 9:42 am

I have been developing a card sorting app (in a different thread) and wanted to try an alternative solution. I have done a fairly comprehensive trawl of the forums and tutorials, and can't find an obvious solution - hence starting a new thread.

What I am trying to achieve is akin to the iPhone screen when you organise the apps - if you drag an icon, all of the other icons shift to accommodate the new position.

Before I try and reinvent the wheel - has anyone tried to create something similar, or know of a plugin that would help with this.

I have found examples where two items swap position on overlap, but would love to have the visual 'shuffle' effect. My initial thoughts are along the line of using an array and pushing values into it on the overlap event and pulling the surplus from the array - then using something like 'litetween' to animate the cards to their new position.
B
8
S
2
G
1
Posts: 45
Reputation: 1,007

Post » Fri Sep 27, 2013 12:16 pm

OK - so what I am thinking is using an array when the cards are placed on the screen - 3 rows to the array - Y0 holds the animation frame of the card, Y1 holds the x position, Y2 holds the Y position.

Is there a way of (on collision of 2 cards) only updating Y0 in the array without changing Y1 & Y2. I imagine that I need to delete the animation frame of the card being dropped, and then push it into the place where it is being dropped.

E.g cards in order

YO 0 1 2 3 4 5 6

Drag card six and drop it on one

Y0 0 6 1 2 3 4 5

After the array is updated, I can then move all the cards to their new position in Y1 & Y2
B
8
S
2
G
1
Posts: 45
Reputation: 1,007

Post » Wed Oct 02, 2013 2:47 pm

I have managed to get this far but am really struggling

Card Rearranger CAPX

The problem is not being able to manipulate one row in an array without changing the values in the rows below, so I have used two arrays - one to manipulate the order of the cards, the second to hold card positions, then use the Array index in the first to find the position in the second. Once new positions are established a function then moves all the cards to their new position.

Works fine on the first move then it all goes horribly wrong.

Please help - I am trying but this is my first attempt - it is driving me mad!!!!
B
8
S
2
G
1
Posts: 45
Reputation: 1,007

Post » Fri Oct 04, 2013 1:36 pm

Anybody? Please - I am going crazy
B
8
S
2
G
1
Posts: 45
Reputation: 1,007

Post » Fri Oct 04, 2013 1:44 pm

Brainfart from someone inexperienced with arrays:

Why not clear the whole array on drag and refill it on drop?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Oct 04, 2013 2:02 pm

Not sure that would work - if i clear the array at any stage then i have lost the order of the cards and this array is the only place that exists - but thanks for the brainfart
B
8
S
2
G
1
Posts: 45
Reputation: 1,007

Post » Fri Oct 04, 2013 2:53 pm

Here's an example without using an array. You could easily add an array to it if you need to store the order.
reorderCards.capx (r146)
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,670

Post » Fri Oct 04, 2013 3:02 pm

Ah mate - that is fantastic - I need to pick this apart and see how it works, but this is exactly what I was working towards.

Thanks lots n more
B
8
S
2
G
1
Posts: 45
Reputation: 1,007

Post » Mon Oct 07, 2013 2:37 pm

Out of interest - what logic would you use to sort through a 2d grid of objects
B
8
S
2
G
1
Posts: 45
Reputation: 1,007


Return to How do I....?

Who is online

Users browsing this forum: NN81, pmerineau and 25 guests