Skip to main content
saratogacoach
Inspiring
October 16, 2012
Question

Shuffling Image Positions

  • October 16, 2012
  • 1 reply
  • 1213 views

If I have 20 images (cut jigsaw puzzle pieces) scattered around the top, sides and bottom of a stage, and want to shuffle their positions upon entering the frame (or using a button), what type of shuffle/swap array would I need to randomly swap their X Y positions? I've looked for examples in solitaire type games, but haven't found any so far.

Any help appreciated.

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
October 16, 2012

If the positions are fixed, shuffle the order of the pieces and plant them per the fixed positions.  If you need to collect their positions first you should be able to loop thru them and collect that info into an aray and then loop thru that array and randomly pick which pieces get placed where.

saratogacoach
Inspiring
October 16, 2012

Hi Ned,

Thank you for this suggestion. Yes, they are fixed positions. Unfortunately, I can't get my brain around: "shuffle the order of the pieces and plant them per the fixed positions." I can hard-code the X and Y position of each piece, but not sure how to store X and Y in an array and then retrieve (maybe, not necessary?).

Ned Murphy
Legend
October 16, 2012

If you have the pieces in an array, which you likely should, you can loop thru that array and record their x/y positions into another array and then use that other array to place a shuffled version of the pieces array.