X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Ftilemap.cpp;h=576cf48674c48b1ce63c52e0876ea142031c1b3f;hb=fea3446f05e1e7673607b835c269d3e8d1929ab3;hp=c923d5deaf03df8d04cfffb57bd78c94ad692189;hpb=d230ce6c64a83daa0b69af8f5f097985cc65d1b3;p=supertux.git diff --git a/src/object/tilemap.cpp b/src/object/tilemap.cpp index c923d5dea..576cf4867 100644 --- a/src/object/tilemap.cpp +++ b/src/object/tilemap.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include "tilemap.hpp" #include "video/drawing_context.hpp" @@ -79,12 +79,16 @@ TileMap::TileMap(const lisp::Lisp& reader, TileManager* new_tile_manager) set_x_offset(v.x); set_y_offset(v.y); } - + std::string draw_target_s = "normal"; reader.get("draw-target", draw_target_s); if (draw_target_s == "normal") draw_target = DrawingContext::NORMAL; if (draw_target_s == "lightmap") draw_target = DrawingContext::LIGHTMAP; + if (reader.get("alpha", alpha)) { + current_alpha = alpha; + } + reader.get("width", width); reader.get("height", height); if(width < 0 || height < 0) @@ -148,7 +152,8 @@ TileMap::update(float elapsed_time) if (amt > 0) current_alpha = std::min(current_alpha + amt, alpha); if (amt < 0) current_alpha = std::max(current_alpha + amt, alpha); } - if (current_alpha < 0.25) set_solid(false); + if ((alpha < 0.25) && (current_alpha < 0.25)) set_solid(false); + if ((alpha > 0.75) && (current_alpha > 0.75)) set_solid(true); } // if we have a path to follow, follow it @@ -162,6 +167,9 @@ TileMap::update(float elapsed_time) void TileMap::draw(DrawingContext& context) { + // skip draw if current opacity is set to 0.0 + if (current_alpha == 0.0) return; + context.push_transform(); context.push_target(); context.set_target(draw_target); @@ -222,7 +230,6 @@ void TileMap::expose(HSQUIRRELVM vm, SQInteger table_idx) { if (name.empty()) return; - if (!walker.get()) return; Scripting::TileMap* interface = new Scripting::TileMap(this); expose_object(vm, table_idx, interface, name, true); } @@ -231,7 +238,6 @@ void TileMap::unexpose(HSQUIRRELVM vm, SQInteger table_idx) { if (name.empty()) return; - if (!walker.get()) return; Scripting::unexpose_object(vm, table_idx, name); } @@ -288,8 +294,8 @@ TileMap::resize(int new_width, int new_height, int fill_id) width = new_width; } -void -TileMap::set_solid(bool solid) +void +TileMap::set_solid(bool solid) { this->solid = solid; } @@ -333,11 +339,28 @@ TileMap::change_all(uint32_t oldtile, uint32_t newtile) } } -void +void TileMap::fade(float alpha, float seconds) { this->alpha = alpha; this->remaining_fade_time = seconds; } + +void +TileMap::set_alpha(float alpha) +{ + this->alpha = alpha; + this->current_alpha = alpha; + this->remaining_fade_time = 0; + if (current_alpha < 0.25) set_solid(false); + if (current_alpha > 0.75) set_solid(true); +} + +float +TileMap::get_alpha() +{ + return this->current_alpha; +} + IMPLEMENT_FACTORY(TileMap, "tilemap");