In my shmup, I want to have three stages, the sky, the atmosphere, and space. To visual these, I want to add a scrolling background, so for example, in the sky, I might have mountains below, and in space, I will have stars and so on. But I don’t know how to do so, and I would also like it so that the tiles are random, so that you don’t have a cloud evey single 16 (or whatever size) pixels.
I don’t have time at the moment to give a proper in-depth answer but…
@filmote’s Steve the Jumping Dinosaur Tutorial demonstrates making a game with a scrolling background. It might not be quite enough for what you’re trying to achieve, but it’ll help you get started at least. Particularly the part about making the ground scroll.
It basically just stores a minimum amount of terrain and then generates new terrain randomly as required. This means terrain can’t be backtracked past a certain point, but for certain games that’s not really an issue.
Alternatively, if you need an effectively* infinite background then you might want to take a look at this old demo of mine:
(* ‘Effectively’ as in not truly infinite but it would take so long to repeat that nobody is going to really notice when it does repeat.)
Which was originally developed as a proof of concept for someone else’s project:
I believe the above topic discusses what the code does at some point and explains some of the concepts behind it, but if not, feel free to ask questions.
If you do use the code in your game though, make sure you stick to the rules of the Apache 2.0 licence by including a copy of the licence, retaining the copyright notice and stating (e.g. in a comment) that you have modified the code.
(Normally I’d explain why/what licences are, but I don’t have time at the moment, so here’s a page that explains why licences are generally needed for published code, and here’s a page that explains the general idea of the Apache 2.0 licence in particular. If those aren’t enough, feel free to ask questions and I (or someone else) will answer when I (or they) can.)
I would have a look at a bunch of different games and see what effect you like.
For example, in the Trials of Astarok I have a created a level which is generated by a seed and is going to be the same each time you play the game (and pick that seed). The ground and sky also produce a ‘parallax’ effect. Trials of Astarok [V1.0]
In CyberHack, the scenes where you move between areas contain totally random levels and will be different each time you try them. It also has the ‘parallax’ trick … CyberHack V1.0
In OBS, the meteors are all random. These could be substituted for mountains or whatever … OBS (One Button Shooter)
Find what you like in these or other games and do what programmers do … repurpose someone else’s code (ie steal!). But always pay respect to the licences