How do I Set position to random IID ?

0 favourites
  • 6 posts
From the Asset Store
*********** Fidget popper tile sets **************
  • Hi. It is a jigsaw puzzle. I have 48 pieces and a slide bar where you can choose then and drag to the screen. This slide bar have 48 "anchors" that I use to hold the pieces position.

    Now, each piece have his position set to an anchor. What I need is to set the pieces position (on the start) to random anchors, so when you slide you see: piece1, piece44, piece16 and so on... instead of: piece1, piece2, piece3 (that I have now).

    Just to show you what I need

    Formulas I tried (the slide bar is vertical, so all the Piece.X is the same, changing just the Y):

    Set Piece position to: Slider.X, Anchor(random(Piece.IID)).Y

    Set Piece position to: Slider.X, random(Anchor(Piece.IID).Y

    Set Piece position to: Slider.X, Anchor(random(Anchor.IID)).Y

    Set Piece position to: Slider.X, Anchor(random(Piece.IID)).Y

    Set Piece position to: Slider.X, Anchor(Piece.IID).Y+random(LayoutHeight)

    Set Piece position to: Slider.X, Anchor(random(0, 47)).Y

    Nom works correctly like expected. I'm shure there's a simple formula that I'm missing. Please help, would appreciate any thoughts!

  • Here's a way to shuffle the pieces and apply them to anchors - you can move the pieces and see the anchors underneath.

    If you're just using single frames for the pieces then I'd suggest sticking all the images as frames in one animation.

    https://www.dropbox.com/s/odo9p34kstf2r ... .capx?dl=0

    Notice that you don't really need the anchors if you use this method, you can just spawn all the pieces. You can then assign a couple of instance variables to the piece to record each instance's starting X,Y position, then you can use those values if you need to reposition them on the sliding bar.

  • mekonbekon Thank you man.

    I don't really understand your capx, the pieces location are in their specific anchor just like my, yellow piece are in yellow anchor, red piece in red anchor and so on.

    What I wish is every time i run the game the pieces go to a random anchor, a simple formula for Y would do it, I still trying to figure her out but she is making herself difficult!

  • mekonbekon Thank you man.

    I don't really understand your capx, the pieces location are in their specific anchor just like my, yellow piece are in yellow anchor, red piece in red anchor and so on.

    What I wish is every time i run the game the pieces go to a random anchor, a simple formula for Y would do it, I still trying to figure her out but she is making herself difficult!

    If you rerun the capx each time you'll see that the order of the anchors and pieces do change.

    If you want to keep the anchor order the same, just add a line of anchors to your layout then spawn the pieces in a similar way to how I've outlined on top of the anchors. Add an instance variable to the anchor (e.g. pieceID and do a check for overlapping with a piece: if overlapping set the anchor variable to the piece frame number.

    As I mentioned above, you don't really need the anchors: you can put all the piece frames on a single object, spawn multiple pieces in a random order and then save their initial position values to instance variables, saving you having lots of extra objects in your layout.

    Hope that helps

  • mekonbekon has provided good example to start with. I also made mini game that shuffle number to pick numbers in correct order: (oops wrong link)

    [EDIT] here it is:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yeah indeed a good example, now I undestand arrays and I could understand your logic , thank you very much, it help me a lot

    Turns out that making puzzles is as complicated as playing it ^^

    Thank you guys!

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