سؤال

I'm trying to create a little game with libGdx. For the level selection, I'd like to have a something similar to the level selection in AngryBirds where you can scroll through a large "map" and then select a level. I know there are several tutorials on the internet and I've read thorugh a lot of them, but none really helped me.

The level selection is not supposed to be paged, it's rather a continuous long map. The way I'd like to set this up is to have on large stage that is larger than the screen with images and buttons for the level selection on it. Then I always want to show a different part of that stage depending on where the user has scrolled to.

Is it possible to set it up this way? How could I implement it? Is it possible to use ScrollPane with one large stage?

هل كانت مفيدة؟

المحلول

Instead of ScrollPane you could simply use a camera. Define your camera viewport to for example 80 width and 45 hight (16/9). Set your cams position to camWidth / 2 camHight / 2 because the camras position is in its middle, and you want to start on (0/0) at the bottom left corner right? Then you can draw your buttons. Draw at (0/0) to draw on the first row and first collumn. Drawing on (90/0) is out of the camera, as you look from (0/0) to (80/45). To scroll your map you could simply do: camera.setPosition(cameraX + some Movement, cameraY) to scroll to the right. Note, that this is only pseudo code and it is important, that you call cam.update() after moving the cam and you use the cams matrix for your spritebatch: batch.setProjectionMatrix(cam.combined). Hope you understand it. If not leave a comment and i will edit.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top