I’m sure this sort of thing has been done in the past but I thought it was pretty cool. Matt suggested early on that we could add some atmosphere to the game by casting light from the ship onto the asteroids. In addition to adding some graphical flair, it could be used to make the game more challenging as distant obstacles would be harder to spot.
I must admit I was initially resistant the idea. Given our limited time I wasn’t sure the extra work was worth the subtle effect it would have on the core game. Also – as any of you that have worked with Android surfaceview will know – there’s only so many pixels you can push to the screen before the framerate starts to take a nosedive. I’ll talk more on that in another post.
After thinking about it for a bit, I decided to spend a little time developing a technique I was using for Badlands (working title!) that screened translucent bitmaps over a sprite to simulate light. Each sprite would be made up of a base layer with no obvious light source, plus four ‘light’ layers, each lit from a different side. Depending on the angle of the light source in relation to the sprite (this is a bit tricky as sprites can rotate), I overlay up to two of these layers on top of the base image – each faded depending on their relative angle. The gif below gives a rough idea of how it looks, it’s actually a lot smoother in-game.
Admittedly, this technique wouldn’t always work (anything with large protrusions would probably look odd), but it works pretty well for our asteroids. It did lower the fps a bit, but I think the effect is worth the hit. I’m still looking into ways of doing this more efficiently – any ideas welcome!