How do I create a random spinner?

  • I need to create a random spinner for a digital board game. I have created something similar once, producing 6 animations and randomizing them, but I believe it's not the better or the right way to do this. Could someone please suggest a better solution? Thanks in advance.

  • You mean random frame of your sprite, right?

    If yes, you can set frame right after create it to random(0, spinner.AnimationFrameCount)

    Notice that you need to set animation speed to 0.

  • I said spinner but I meant a roulette like a "fortune wheel". I would like to use a code (maybe with the rotate behavior for example) instead of creating a spin animation.

  • Ah I see, you can have a array to contain all your rewards.

    Then create the name reward around the center with this

    Repeat Array.Width times: Create Object: at position x,y

    Set text to Array.At(loopindex )

    Then set position

    X: center.X + radius *cos(360/Array.Width*reward.IID)

    Y: center.Y + radius *sin(360/Array.Width*reward.IID)

    And set angle to angle(center.X, center.Y, reward.X, reward.Y)

    At last you will need to pin it to the center.

  • And here is the screenshot of event sheet:

  • And here is the screenshot of event sheet:

    Hi Maverick1912

    Thank you! I think I understood it very well after I saw the script that you shared, but I still have some doubts. Could you please answer them?

    - I defined the array's width to 4 but I am getting 14 rewards around the circle. Do you know why?

    - I intend to use images instead of text. How can I do to detect the image that was awarded? I would like to make it blink.

    - in this example, the circle rotates and the pointer does not move. I would like to offer two modes: this one and a reverse of this? (the circle does not move and the pointer rotates)

  • Hi RBuster, these are my answer

    - I defined the array's width to 4 but I am getting 14 rewards around the circle. Do you know why?

    -> Yes, you need to set the width of the array to 0 in the properties section.

    - I intend to use images instead of text. How can I do to detect the image that was awarded? I would like to make it blink.

    -> You can add the value of the array into an instance variable of sprite.

    - in this example, the circle rotates and the pointer does not move. I would like to offer two modes: this one and a reverse of this? (the circle does not move and the pointer rotates)

    -> You can set speed to the pointer to make it rotates, if you want to reverse, add (-) into the speed.

  • Thanks for answering.

    You can add the value of the array into an instance variable of sprite.

    But how can I do to detect the image that was awarded?

    My last questions:

    - I intend to create an APK with this game(?). Can I load the images from an external folder or even from a URL?

    - is it possible to produce this APK with a transparent background? (showing the mobile desktop that is behind it)

  • But how can I do to detect the image that was awarded?

    -> You can use on overlapping with the pointer to get the instance value

    I don't know the solution for your last two question about APK. Hope someone would know the answer.

  • Ok. I will give it a try. Thanks

    Do you know if it's possible to rotate de image/text keeping them in the same position, as the roulette wheel is spinning?

  • Do you know if it's possible to rotate de image/text keeping them in the same position, as the roulette wheel is spinning?

    Use the pin behavior possibly.

  • > Do you know if it's possible to rotate de image/text keeping them in the same position, as the roulette wheel is spinning?

    Use the pin behavior possibly.

    I intend to use it to allow the images to rotate with the wheel, but can I use it to keep the same position and the original angle? I don't want the images to get upside down.

  • The manual is your friend : construct.net/en/make-games/manuals/construct-3/behavior-reference/pin

    Yes, pin it using "Position only" and the angle will be kept the original angle.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The manual is your friend : construct.net/en/make-games/manuals/construct-3/behavior-reference/pin

    Coincidently, I've checked the manual after my post and I confirmed this information. Sorry about that.

  • Hi Maverick1912

    I am rotating the pointer instead of the board and I would like to stop this pointer in the middle of the place on board when the rotation is finished. I am using 3 different boards with 4, 6 and 8 places. Could you please help me to get it working?

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