[RGSS3] BITMAP LAYERING PROBLEM

Posts

Pages: 1
Craze
why would i heal when i could equip a morningstar
15170
I know a few people here are handy with VX/Ace coding, so... here's hoping. I'm working on an extension to Yanfly's party selection script that shows all of the passive effects a character has.



I think the problem is pretty apparent, haha.

Basically, I draw the character's portrait and some filled rectangles, but they completely remove portions of the portrait, making it look stupid. How can I layer them? Is there a z variable for bitmaps?

Here's the relevant code:

def draw_actor_face(actor, x, y, enabled = true)
    draw_face(actor.name + " Portrait", x, y, enabled)
  end

  #--------------------------------------------------------------------------

  def draw_face(face_name, x, y, enabled = true)
    bitmap = Cache.picture(face_name)
    rect = Rect.new(0,0,272,288-2)
    contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
    bitmap.dispose
  end

def draw_actor_effects(actor, dx, dy)
    dw = contents.width - 4
    rect = Rect.new(dx+1, dy+1, dw - 2, line_height - 2)
    contents.font.size = YEA::PARTY::STAT_FONT_SIZE
    colour = Color.new(0, 0, 0, translucent_alpha/2)
    array = actor.skills
    cx = 4
    for effect in array
      next if effect.stype_id != 5
      contents.fill_rect(rect, colour)
      icon = effect.icon_index
      text = effect.description

      draw_icon(icon, rect.x, rect.y)
      change_color(normal_color)
      draw_text(rect.x+24, rect.y, rect.width-24, line_height, text, 0)
      rect.y += line_height
    end
    reset_font_settings
  end

Thank you ~
Rhyme
Tear Harvester Rhyme
7582
You can
a) Draw the rects before the face (This will result in the face on top of the black boxes though!)

b) Make another bitmap and blt the it to contents. (you might also want to draw the text on the said bitmap as opposed to contents too!)
  new_bitmap = Bitmap.new(contents.width, contents.height)

rect = Rect.new(dx+1, dy+1, dw - 2, line_height - 2)
color = Color.new(0, 0, 0, translucent_alpha/2)
new_bitmap.fill_rect(rect, color)
contents.blt(0, 0, new_bitmap, new_bitmap.rect)
new_bitmap.dispose

not sure if this method will need you to dispose the new bitmap or not afterwards but, this is what I usually do!

c) Make a sprite layered above it and draw your transparent stuff there (not recommended unless you have something animating that would take a lot of resources to redraw per frame! for this instance, you probably don't want to do this)
Craze
why would i heal when i could equip a morningstar
15170
Used method b...



...and it works! Hooray!

Thanks, rhyme.

EDIT: I kept the dispose in; when I'm feeling brave I'll take it out and see if it freaks.
Pages: 1