X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbackground.cpp;h=56506e5ba592b45eaa5fd3a7b2da9254a72ef9c5;hb=875ef8eb7e93726bc67dfa7f05da946250e588d4;hp=b8d0ecc945d3998e849967bcdba0600031e66986;hpb=1e7faec8333b84dc75c9f1eaf3eab3d5821fa14a;p=supertux.git diff --git a/src/background.cpp b/src/background.cpp index b8d0ecc94..56506e5ba 100644 --- a/src/background.cpp +++ b/src/background.cpp @@ -17,6 +17,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include + #include "background.h" #include "app/globals.h" #include "camera.h" @@ -24,13 +26,14 @@ #include "utils/lispwriter.h" Background::Background() - : type(INVALID), image(0) + : type(INVALID), layer(LAYER_BACKGROUND0), image(0) { } Background::Background(LispReader& reader) - : type(INVALID), image(0) + : type(INVALID), layer(LAYER_BACKGROUND0), image(0) { + reader.read_int("layer", layer); if(reader.read_string("image", imagefile) && reader.read_float("speed", speed)) { set_image(imagefile, speed); @@ -69,6 +72,7 @@ Background::write(LispWriter& writer) writer.write_int_vector("top_color", bkgd_top_color); writer.write_int_vector("bottom_color", bkgd_bottom_color); } + writer.write_int("layer", layer); writer.end_list("background"); } @@ -107,24 +111,25 @@ Background::draw(DrawingContext& context) /* In case we are using OpenGL just draw the gradient, else (software mode) use the cache. */ if(use_gl) - context.draw_gradient(gradient_top, gradient_bottom, LAYER_BACKGROUND0); + context.draw_gradient(gradient_top, gradient_bottom, layer); else { context.push_transform(); context.set_translation(Vector(0, 0)); - context.draw_surface(image, Vector(0, 0), LAYER_BACKGROUND0); + context.draw_surface(image, Vector(0, 0), layer); context.pop_transform(); } } else if(type == IMAGE) { - int sx = int(-context.get_translation().x * speed) - % image->w - image->w; - int sy = int(-context.get_translation().y * speed) - % image->h - image->h; + if(!image) + return; + + int sx = int(-context.get_translation().x * speed) % image->w - image->w; + int sy = int(-context.get_translation().y * speed) % image->h - image->h; context.push_transform(); context.set_translation(Vector(0, 0)); for(int x = sx; x < screen->w; x += image->w) for(int y = sy; y < screen->h; y += image->h) - context.draw_surface(image, Vector(x, y), LAYER_BACKGROUND0); + context.draw_surface(image, Vector(x, y), layer); context.pop_transform(); } }