Evgenij

Veteran
Veteran
Joined
Aug 28, 2013
Messages
349
Reaction score
100
First Language
German
Primarily Uses
N/A
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?
 
Last edited by a moderator:

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
608
Reaction score
320
First Language
German
Primarily Uses
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.
 
Last edited by a moderator:

Evgenij

Veteran
Veteran
Joined
Aug 28, 2013
Messages
349
Reaction score
100
First Language
German
Primarily Uses
N/A
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.
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
608
Reaction score
320
First Language
German
Primarily Uses
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)
 
Last edited by a moderator:

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
stretch_blt(dest_rect, src_bitmap, src_rect[, opacity])
Use that info for the method

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.
 
Last edited by a moderator:

Latest Threads

Latest Posts

Latest Profile Posts

Doing RPG Maker News for 21st September 2021


Malak is still waiting for Dark Deception Chapter 4... This was him yesterday after another sugar crash.
Again, he's fine. He's just bored at this point, considering he's exhausted his entire vacation bucket list.
Am I the only one who files custom resources under specific folders to remember who to credit? :kaoswt2:
1632263519730.png
I always smile to myself when I see someone do the "immediate halt and spin around" from forgetting something. I find it sort of endearing how we all do it without ever being taught to.

Forum statistics

Threads
115,260
Messages
1,088,434
Members
149,864
Latest member
ratbyte
Top