Hello, I’m trying to make a slot machine just as a fun project. Here is a link to it if you’re interested.
https://dl.dropboxusercontent.com/u/24222531/SLOTS.zip
I made this simple one in about an hour, but I want to improve it.
In my first attempt, each slot machine “reel” consists of 3 sprite images placed in a column. The images then flip to the next image, making a cheap sort of scrolling.
I’m interested in using an actual scrolling sprite to implement my slot machine reels, but I am confused how to do it.
I found this tutorial https://code.google.com/p/libgdx-users/wiki/ScrollingTexture which helped me get the basics of scrolling a texture, but now I am struggling with indexing where the actual images are. Here is some code:
public ScrollWheel(){
Texture tex = new Texture(Gdx.files.internal("assets/wheel2.png"));
tex.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
sprite = new Sprite(tex);
sprite.setSize(64, 256);
sprite.setPosition(150, 120);
}
public void update() {
scrollTimer += Gdx.graphics.getDeltaTime();
if (scrollTimer > 1.0f) {
scrollTimer = 0.0f;
}
sprite.setV(-scrollTimer);
sprite.setV2(-scrollTimer + 3f/6f);
}
This successfully makes the image as large as I want, and also makes it scroll downwards like a slot machine reel would. Since my source image consists of 6 seperate images, each individual picture on the reel is some N/6 (thus the 3f/6f makes my reel display 3 images out of 6 at once).
My issue is identifying where the actual images are on the scrolling texture. When the player stops the reel, it needs to stop at the nearest actual image at the midpoint of the reel. This is quite tricky. Does anyone have any suggestions of how I would accomplish this? The V and V2 coordinates are a bit confusing.
Another method I considered was to compose a larger “reel” texture from the 6 individual textureRegions, and maybe use those as indexes somehow?