From 07ccc15fc2f0f2abc7f67b51bbfcdc673f6b2869 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 16 Jun 2012 18:02:56 +0300 Subject: Allow node cracking animations of any length --- src/tile.cpp | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'src/tile.cpp') diff --git a/src/tile.cpp b/src/tile.cpp index 92c56c277..f0b905c4a 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -502,6 +502,11 @@ u32 TextureSource::getTextureId(const std::string &name) // Overlay image on top of another image (used for cracks) void overlay(video::IImage *image, video::IImage *overlay); +// Draw an image on top of an another one, using the alpha channel of the +// source image +static void blit_with_alpha(video::IImage *src, video::IImage *dst, + v2s32 src_pos, v2s32 dst_pos, v2u32 size); + // Brighten image void brighten(video::IImage *image); // Parse a transform name @@ -1266,7 +1271,8 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, It is an image with a number of cracking stages horizontally tiled. */ - video::IImage *img_crack = sourcecache->getOrLoad("crack.png", device); + video::IImage *img_crack = sourcecache->getOrLoad( + "crack_anylength.png", device); if(img_crack && progression >= 0) { @@ -1305,11 +1311,13 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, } else { - img_crack_scaled->copyToWithAlpha( + /*img_crack_scaled->copyToWithAlpha( baseimg, v2s32(0,0), core::rect(v2s32(0,0), dim_base), - video::SColor(255,255,255,255)); + video::SColor(255,255,255,255));*/ + blit_with_alpha(img_crack_scaled, baseimg, + v2s32(0,0), v2s32(0,0), dim_base); } } @@ -1721,6 +1729,30 @@ void overlay(video::IImage *image, video::IImage *overlay) } } +/* + Draw an image on top of an another one, using the alpha channel of the + source image + + This exists because IImage::copyToWithAlpha() doesn't seem to always + work. +*/ +static void blit_with_alpha(video::IImage *src, video::IImage *dst, + v2s32 src_pos, v2s32 dst_pos, v2u32 size) +{ + for(u32 y0=0; y0getPixel(src_x, src_y); + video::SColor dst_c = dst->getPixel(dst_x, dst_y); + dst_c = src_c.getInterpolated(dst_c, (float)src_c.getAlpha()/255.0f); + dst->setPixel(dst_x, dst_y, dst_c); + } +} + void brighten(video::IImage *image) { if(image == NULL) -- cgit v1.2.3