Hi, what would be the best way to scale the size of actor faces?
This is the draw_face method:
def draw_face(face_name, face_index, x, y, enabled = true) bitmap = Cache.face(face_name) rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96) contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha) bitmap.dispose endNow Im clueles what to do, because the bitmap contains sets of faces.
Lets say I want to scale the drawn face by the factor 0.75, so it will be drawn with a size of 75 * 75 instead of 96 * 96.
I dont want that the source faceset file will be changed, it should be the same size as the default faceset size.
My idea was to resize the whole bitmap at first by the factor and after that
use something like this for the rect:
factor = 0.75new_size = factor * 96rect = Rect.new(face_index % 4 * new_size, face_index / 4 * new_size, new_size, new_size)But I cant do it because I dont know how to resize the bitmap.
*edit*
This is how my solution looks like:
def draw_face(face_name, face_index, x, y, enabled = true) f = 0.75 n = 96 * f source_bitmap = Cache.face(face_name) target_bitmap = Bitmap.new(source_bitmap.width * f, source_bitmap.height * f) target_bitmap.stretch_blt(target_bitmap.rect, source_bitmap, source_bitmap.rect) rect = Rect.new(face_index % 4 * n, face_index / 4 * n, n, n) contents.blt(x, y, target_bitmap, rect, enabled ? 255 : translucent_alpha) source_bitmap.dispose target_bitmap.dispose endIs it ok or do you have something better?
Scale Actor Faces / resize bitmap
● ARCHIVED · READ-ONLY
-
-
Disposing bitmaps retrieved from the cache module should be an exception, since the main purpose of the cache module is to load a bitmap once and store it for future use.
While it should not really matter for facesets, bitmap objects from the cache can be shared by multiple sprites, so if you dispose the bitmap object all those sprites will be affected.
Instead of creating a scaled target bitmap, you could also use stretch_blt directly to apply the source bitmap to the windows contents. -
Yeah this is the case but im wondering why the bitmap gets disposed in the default code also:
def draw_face(face_name, face_index, x, y, enabled = true) bitmap = Cache.face(face_name) rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96) contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha) bitmap.dispose endAnd my head is struggling cause I cant figure out how to use the stretch_blt directly without creating a target_bitmap.
Thanks for your response. -
Mmm, I didn't remember the faceset graphic was disposed by default... Well, while I don't see the point in using the cache module to retrieve a bitmap that is disposed right away, I can hardly argue against it. :)
When using stretch_blt the first argument also contains the width and height of the scaled image, for example:
dest_rect = Rect.new(x, y, 96 * f, 96 * f) -
Use that info for the methodstretch_blt(dest_rect, src_bitmap, src_rect[, opacity])
It's indeed weird that the default code sometimes disposes Cached images. It's probably to keep the RAM usage low. But... To me it makes no sense.