pos(),
speed(),
speed_y(),
+ scroll_speed(),
+ scroll_offset(),
image_top(),
image(),
image_bottom()
pos(),
speed(),
speed_y(),
+ scroll_speed(),
+ scroll_offset(),
image_top(),
image(),
image_bottom()
speed = 1.0;
speed_y = 1.0;
+ reader.get("scroll-offset-x", scroll_offset.x);
+ reader.get("scroll-offset-y", scroll_offset.y);
+
+ reader.get("scroll-speed-x", scroll_speed.x);
+ reader.get("scroll-speed-y", scroll_speed.y);
+
reader.get("layer", layer);
if(!reader.get("image", imagefile) || !reader.get("speed", speed))
throw std::runtime_error("Must specify image and speed for background");
}
void
-Background::update(float)
+Background::update(float delta)
{
+ scroll_offset += scroll_speed * delta;
}
void
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 sx = int(scroll_offset.x + pos.x-context.get_translation().x * speed) % w - w;
+ int sy = int(scroll_offset.y + 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();
Vector pos; /**< coordinates of upper-left corner of image */
float speed; /**< scroll-speed in horizontal direction */
float speed_y; /**< scroll-speed in vertical direction */
+ Vector scroll_speed;
+ Vector scroll_offset;
std::auto_ptr<Surface> image_top; /**< image to draw above pos */
std::auto_ptr<Surface> image; /**< image to draw, anchored at pos */
std::auto_ptr<Surface> image_bottom; /**< image to draw below pos+screenheight */