- if(type == GRADIENT) {
- context.push_transform();
- context.set_translation(Vector(0, 0));
- context.draw_surface(image, Vector(0, 0), layer);
- context.pop_transform();
- } else if(type == IMAGE) {
- 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);
- context.pop_transform();
+ if(image.get() == NULL)
+ return;
+
+ int w = (int) image->get_width();
+ int h = (int) image->get_height();
+ int sx = int(pos.x-context.get_translation().x * speed) % w - w;
+ int sy = int(pos.y-context.get_translation().y * speed_y) % h - h;
+ int center_image_py = int(pos.y-context.get_translation().y * speed_y);
+ int bottom_image_py = int(pos.y-context.get_translation().y * speed_y) + h;
+ context.push_transform();
+ context.set_translation(Vector(0, 0));
+ for(int x = sx; x < SCREEN_WIDTH; x += w) {
+ for(int y = sy; y < SCREEN_HEIGHT; y += h) {
+ if (image_top.get() != NULL && (y < center_image_py)) {
+ context.draw_surface(image_top.get(), Vector(x, y), layer);
+ continue;
+ }
+ if (image_bottom.get() != NULL && (y >= bottom_image_py)) {
+ context.draw_surface(image_bottom.get(), Vector(x, y), layer);
+ continue;
+ }
+ context.draw_surface(image.get(), Vector(x, y), layer);
+ }