I have a slot game with 5 columns (reels). The symbols on each reel are in a specific order. The player can see 4 symbols on a reel at time. The symbols are stacked in a vertical line and move downward. When they pass a certain y point, they reset back to the top. When the player presses play the game selects a random symbol for each reel and the following 3 symbols in their specific order. Each symbol has 12 animations on it (sprite manager).
Just before the reels stop spinning, we change the animation on 4 symbols to the randomly selected symbols. Again, this needs to happen just before the reel stops so the new symbols can slide perfectly into their place.
I currently have it set up where at a certain time before the reel stops (like .25 of a second), if the top symbol is between two certain y values (above the reels), we change it to the randomly selected symbol, and then change the following 3 as well. This is SORT OF working. It isn’t consistant or reliable. Most of the time the proper symbols will change, but other times (Because this is time based and because it runs on different devices) it will stop at the wrong symbol location (usually + or - 1).
WHAT I NEED: To get these reels to stop somehow mathematically vs time based (because time is inconsistent). The problem is we will never know which symbols to change because the reels are constantly spinning and they have to stop when they stop no matter what (meaning we cant assign 4 specific symbols to be the changing ones and then move them in to place, because they may be 20 symbols above the reel, and we only have time to scroll through 10).
I need the correct symbols to change just before they move down into the visible reel columns. Any ideas? Is this confusing?
I’m not quite sure how you’ve currently got this working. I think you are saying that the symbols “walk” downward (ie, the bottom one gets moved back to the top once it goes out of view to create the impression of a continuous loop). Are you letting an animation on each symbol change the picture on a time basis?
One way to handle this might be to use a so-called “circular buffer”. This is just an array that uses an extra function to make the indices wrap around:-
If you pass this function an index which is off the end of the array, it will wrap it round to the start of the array. Likewise, a negative index will be converted to one at the end of the array. You would start with an array large enough to hold the whole reel and then fill it with random elements. You also need a marker integer to remember which item on the reel is currently the bottom one. Then, code the visible representation of the reel so that it can be updated in a step that takes place over a chosen timeframe. A step, here, is simply the operation of sliding all the symbols downward until one disappears from view, at which point it is replaced at the top. At the end of each step, increment the marker to point to the next array element and choose the incoming symbol picture based on the value that follows it in the array. If you use the circular buffer indexing for the marker increment and finding the following element, you will get a continuous cycle of elements.
From then on, it is just a matter of controlling the speed of the reel. Cycle it fast for a while, then just before the last four steps, gradually slow the step speed until the reel comes to a standstill as the final symbol gets cycled in.
It’s not easy to suggest exactly what code you should use for this without seeing what you’ve already got but it is likely that the circular buffer thing can be added to your existing script fairly easily.