Comments (2)
Hi Chris,
Thanks for getting in touch and including a screenshot as well as some details about your project, it really helps to understand what you are trying to create - looks interesting by the way!
My first thought would be to do something with SessionStorage or LocalStorage which is an easy way to store information in the user's browser and read it back. I found this tutorial that seems like a good intro https://alligator.io/js/introduction-localstorage-sessionstorage/
Using this you could store a couple of things: the spin level, and also an array of the segment information for each of the levels. In the tutorial above see the section called "Storing Json Objects" to see how you can store an array of information like the segments.
I imagine the logic of the code could work something like this...
- User loads the page
- Check if local storage exists
- IF yes then get the spin level from local storage
- Get the segment information for that level
- Create the Winwheel using the normal config but passing the segments information retrieved from local storage (remember to JSON.parse it to turn it back in to a json object first)
- User spins the wheel (you might want to pre-determine the result, more on this later)
- Use the getIndicatedSegmentNumber to know what segment the user landed on
- Update the segments information in the local storage to swap to the grayed image and also perhaps set a flag or something to indicate the segment has already been landed on.
- Check if all segments have been visited for this level, and if so increment the spin level and update the local storage
If at step 2 the local storage does not exist then add the spin level and segment information in its initial state to the local storage.
Now there is still the issue of preventing the user from landing on a segment already visited, I would probably work out before the spinning what segment the user will stop on by checking which segments had not already been visited and randomly (or not so randomly) picking one.
You may have already seen this when looking at the Winwheel.js documentation but http://dougtesting.net/winwheel/docs/tut14_setting_the_prize shows how to specify what segment the user will land on - in particular note the let stopAt = theWheel.getRandomForSegment(segmentNumber); in one of the examples.
Hope this helps.
Cheers,
DouG.
from javascript-winwheel.
Thanks, DouG! Really appreciate the insights. I'll dive in over the next few weeks and see what I come up with. Will show you an update when it gets further along!
from javascript-winwheel.
Related Issues (20)
- option to set winning field HOT 1
- Curved text causes spacing problems. HOT 1
- Image per segment not working
- Bug with use of Math.Random()
- Multiple independent wheels on the same page HOT 1
- Can you please add version 2.8.0 to jsdelivr? HOT 2
- Insert Image on a Segment
- Is possible to use emojis on segments? HOT 2
- Different starting angle because of the drag animation HOT 1
- Wheel lags/freezes while spinning HOT 1
- Cursive Font Family text causes spacing and rendering text problems
- Two weels at the same time HOT 1
- deleteSegment will not delete first segment
- The site of winwheel tutorials is not available HOT 1
- Problem with custom fonts
- TweenMax is not defined HOT 1
- I want to loop object into segments , I try this but not working.
- I want draw segmentImage without margin between each segements. HOT 2
- I want to get segment size, but I cannot get it.
- How to optimization on mobile?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javascript-winwheel.