# Creating a space texture that'll tile relatively well

This topic is 4962 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm writing a 2d space game. The world is infinite. However, the ship is always at the center of the screen, so I need to give the user a frame of reference to know their ship is moving. The best thing I could think of is a texture for the background, with lots of stars, etc. The trick is not making it look obvious that it's tiled. Would it be better to generate a really large texture? Or are there textures out there that would fit this? I've been unable to find any so far. Thanks. -Nick

##### Share on other sites
Couldn't you generate random stars and their velocities/positions/sizes on the fly?

##### Share on other sites
Since the stars are far away, they'd be static. But yes, I suppose I could generate their positions on the fly with a seeded random number generator. The trick would be getting a decent equation for the area. Any advice on that?

##### Share on other sites
Quote:
 Original post by nickwintersSince the stars are far away, they'd be static. But yes, I suppose I could generate their positions on the fly with a seeded random number generator. The trick would be getting a decent equation for the area. Any advice on that?
What do you mean equation for the area?

How I've done it in the past:

Have an array of NUM_OF_STARS star objects.

Generate each star's random location on screen, it's size and it's single dimensional velocity. Then, every frame, move the stars "down" by their respective velocity. When one falls off the screen, generate a new velocity and single dimensional position to be placed at the side of the screen you're heading in.

Does that sound like what you're aiming for?

##### Share on other sites
I think there are two ways to solve it:

1) have a really big texture. If it's big, you won't catch the repetition so much because there is a lot of detail to keep track of mentally. When i say big, i mean about screen size or a significant portion thereof.

2) have a really sparse texture. This is the opposite trick. There is not enough detail to keep track of.

Personally i would go with option number one. If you want it, you are free to use a texture i made for a website. It works very well because it's large enough not to notice much repetition and i also JPEG'd the snot out of it to reduce bandwidth. It still looks good because it's dark. In a game, you would not notice it's chunkiness. Feel free to use it if you want. It tiles very well:

##### Share on other sites
I'd just go with randomly-placed stars. Don't worry too much about getting an even distribution; randomness usually takes care of itself that way (and besides, a certain amount of clustering for stars is natural). Just let the stars wrap around the screen when they go off one edge. It's subtle enough that most people won't notice (assuming you use small stars), and those who do probably won't care.

##### Share on other sites
Many 2d games generate stars on-the-fly, but also have a background image. About the background texture... it depends how much you want to work on it.

To get a tiling texture you need something similar to what leiavoia suggested. You can use that one or make your own - just be sure you use the offset filter in photoshop (there is smth similar in GIMP) to make it tile.

After that you could use some alpha-blended images (of far-away stars or halos) randomly placed to simulate variation.

##### Share on other sites
A good way to add not only Movement but also depth would be to use parallax scrolling. Instead of having all the stars move the same speed, set up several different "layers" of stars, which scroll past at different speeds. The closer ones will move fastest, the next layer will move slower, and so on. You could make the effect even more pronounced if you make the closest stars brighter or bigger.

The easiest way to do this effect is with random dots. Just define an array of 2D poins, then go through and move and draw each one. if it moves off the screen, give it a new random x positions (If you're scrolling vertically) and move it to the top of the screen. If you use three of these arrays scrolling at different speeds, (and drawn at different sizes) you should have a really nice effect.

PS.
Also try adding a background behind it all, showing nebula or something. It doesn't have to move, the layers of stars will have enough motion

1. 1
2. 2
3. 3
frob
20
4. 4
Rutin
19
5. 5

• 32
• 13
• 11
• 9
• 18
• ### Forum Statistics

• Total Topics
632555
• Total Posts
3007066

×