Sprite shuffling like on IOS home screen

0 favourites
  • 9 posts
From the Asset Store
Simple but fun word game. Restore an original word from shuffled letters.
  • 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.

  • 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

  • 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!!!!

  • Anybody? Please - I am going crazy

  • Brainfart from someone inexperienced with arrays:

    Why not clear the whole array on drag and refill it on drop?

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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)

  • 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

  • Out of interest - what logic would you use to sort through a 2d grid of objects

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