I am a very beginner in game development. All I want to achieve in the beginning is a free scrollable background like in a strategy game with my custom graphics. In my case it is supposed to be a 2d city map where the user can select buildings. How can I achieve that as easy as possible in android? With OpenGL? Die you have any examples especially for this scrolling functionality?
-
\$\begingroup\$ You can achieve this effect by adding any background velocity when the character is stopped. Let's set this speed to 5. Assuming your character has a speed of 10. When it goes forward (right) the background speed will be 15 and when it goes backwards (left), the speed will be -5. That's if I understood your question. \$\endgroup\$– Boneco SinforosoCommented Apr 20, 2019 at 0:57
3 Answers
I think you should go with frameworks like Libgdx rather than using directly OpenGL. Libgdx allow you to draw graphical assets and program interactivity with them.
Here is some starting points :
- Libgdx wiki on Github
- Libgdx official documentation
-
\$\begingroup\$ I don't think this answers the question, OP is using OpenGL and a scrolling effect is easy to do. \$\endgroup\$ Commented Nov 17, 2018 at 18:33
If you want the buildings in the backgroudn to be clickable you could create different classes for each building, assign an image to the object and use ArrayLists to determine how many you would like in the background.
You would have to run a thread in your main class to move the buildings either right or left, check the locations and if x - image.getWidth < 0
then the whole building has left the screen, this means another building needs to be added to the right.
I had a similar problem when I wanted to create a scrolling background. I found the following tutorial (in Java) which is quite easy and worked:
http://gamecodeschool.com/android/coding-a-parallax-scrolling-background-for-android/