Friday, February 27, 2015

Moving Objects and Sprite Manager - Part 8

This is part 8 of the series. You are suggested to read the whole series from the beginning. You may find the whole series in the Featured page.

Scrolling Background

We will use a looping background created by ansimuz.

You may find the original collection at :

The author release the file under the CC0 license. In summary, the license allow you to use it in your own game, even for commercial purpose.

You may download the file

We will use the file desert-backgorund-looped.png inside the zip file.

This is a looping background. That means if we cut the bottom row of the image, and then paste it to the top, we still have a continuous image. Hence the scrolling is as simple as: Note that we are using the same technique in Optimized flood filler to access the pixel array of the image. This is much faster than the getPixel() and setPixel() API.

Reading image from zip file

We will read directly from the zip file so that we don't need to uncompress the file to the harddrive. The source code for reading zip file is defined in readZipImage() in the demonstration. The reason to read directly from zip file is that we may redistribute other people artwork in an unmodified form. This typically fulfill most of the license requirement in

There are many free artworks available in However, you must read the license of the individual entry before using it. Not every entry is released under CC0. Different authors may submit their work under different licenses. For example, many licenses require you to attribute the original author. Just like what I am doing below :

You may have a look at Best Practices for attribution


You will need and in the same folder.

Compile and run

java Scroller

No comments:

Post a Comment