diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 18db3a55f..7645e205a 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -262,6 +262,10 @@ Advanced texture modifiers: Apply a mask to the base image. The mask is applied using binary AND. + [sheet:x:, + Retrieves a tile at position x,y from the base image + which it assumes to be a tilesheet with dimensions w,h. + [colorize: Colorize the textures with given color as ColorString diff --git a/src/tile.cpp b/src/tile.cpp index d2b88a79c..faeab6e59 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -1589,6 +1589,50 @@ bool TextureSource::generateImagePart(std::string part_of_name, << filename << "\"."; } } + /* + [sheet:WxH:X,Y + Retrieves a tile at position X,Y (in tiles) + from the base image it assumes to be a + tilesheet with dimensions W,H (in tiles). + */ + else if (part_of_name.substr(0,7) == "[sheet:") + { + if(baseimg == NULL){ + errorstream<<"generateImagePart(): baseimg != NULL " + <<"for part_of_name=\""< img_dim = baseimg->getDimension(); + core::dimension2d tile_dim(v2u32(img_dim) / v2u32(w0, h0)); + + video::IImage *img = driver->createImage( + video::ECF_A8R8G8B8, tile_dim); + if(!img){ + errorstream<<"generateImagePart(): Could not create image " + <<"for part_of_name=\""<fill(video::SColor(0,0,0,0)); + v2u32 vdim(tile_dim); + core::rect rect(v2s32(x0 * vdim.X, y0 * vdim.Y), tile_dim); + baseimg->copyToWithAlpha(img, v2s32(0), rect, + video::SColor(255,255,255,255), NULL); + + // Replace baseimg + baseimg->drop(); + baseimg = img; + } /* [colorize:color Overlays image with given color