How do I Set position to random IID ?

Just started using Construct 2? Post your questions here

Post » Wed Apr 19, 2017 3:07 pm

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!
"Do what you must" -The Elder (Titan Souls)
B
27
S
13
G
4
Posts: 73
Reputation: 4,311

Post » Wed Apr 19, 2017 5:49 pm

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.
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Wed Apr 19, 2017 6:37 pm

@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!
"Do what you must" -The Elder (Titan Souls)
B
27
S
13
G
4
Posts: 73
Reputation: 4,311

Post » Wed Apr 19, 2017 8:16 pm

Fenix18 wrote:@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 :)
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Thu Apr 20, 2017 8:39 pm

@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: how-do-i-picking-numbers-game_t130154?start=10
ImageImage
B
108
S
49
G
23
Posts: 783
Reputation: 22,611

Post » Fri Apr 21, 2017 9:06 pm

Yeah indeed a good example, now I undestand arrays and I could understand your logic @mekobekon , thank you very much, it help me a lot :D
Turns out that making puzzles is as complicated as playing it ^^
Thank you guys!
"Do what you must" -The Elder (Titan Souls)
B
27
S
13
G
4
Posts: 73
Reputation: 4,311


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests