1
\$\begingroup\$

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?

\$\endgroup\$
  • \$\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 Sinforoso Apr 20 at 0:57
1
\$\begingroup\$

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 :

\$\endgroup\$
  • \$\begingroup\$ I don't think this answers the question, OP is using OpenGL and a scrolling effect is easy to do. \$\endgroup\$ – TomTsagk Nov 17 '18 at 18:33
1
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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/

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.