Spin Wheel Game with Result Action

Hi, in the forum i found some posts for a spin wheel game... Spin wheel game - #7 by Ed_Sager

Is there a way, when the wheel stopped, to check if its a winning field and then to show for example a winning animation?!

thx, best jan

There are probably a few ways to do this.

In the code we add an array of winners.

 // Helpers
 const winners = ["California Tortilla","Uptown Cafe","Pho 75 - Rosslyn","Starbucks"]

The canvas code already determines when it is finished in the drawNeedle: function()
It also records what segment is being pointed at.

So in the drawNeedle: function() we can add a global var to be assigned the last segment that is pointed at when finished.
We use a global so we can easily access it from outside one functions scope to another.
(Probably could be made one of the canvas's init properties)

 // assign last pointed to global var
window.winner = wheel.segments[I]

We then add a check in the OnTimerTick() function, to check against the window.winner array and in this case change scene accordingly.

//== Check for Winner
 		if (winners.includes(window.winner)){
 		hypeDocument.showSceneNamed('Winner', hypeDocument.kSceneTransitionCrossfade, 1.1)
 		} else {
 		hypeDocument.showSceneNamed('Loser', hypeDocument.kSceneTransitionCrossfade, 1.1)

wheelofnames mhv1.hype.zip (58.4 KB)


so cool! thx!!

1 Like