Help - Search - Members - Calendar
Full Version: Displaying a Reversed Image
RPG RPG Revolution Forums > Scripting > Script Development and Support > RGSS
lemonairable
How do you draw a reversed image with RGSS? As in, if I want to display a character portrait facing right at one point, and facing left at another, how would I do that? I think it would probably be a simple code thing, right?
Kread-EX
You can but it's a slow process so unless the picture is small you'll be better with just making a flipped version in an image editing program.
Do you intend to do that in an event or within a script?

EDIT: Disgerard what I just stroke. Actually, it's much faster that I expected. But the last question remains: do you want to do it on the map or within a script?
Xim
QUOTE (Kread-EX @ May 26 2011, 11:42 AM) *
You can but it's a slow process so unless the picture is small you'll be better with just making a flipped version in an image editing program.


This might actually work out better for asymmetrical characters (ie: a character with an eye-patch) so his eye-patch won't switch eyes (although you'd have to make a new picture).
lemonairable
I want to do it within a script.
Specifically, in battles.
Kread-EX
Okay. What exactly do you want to flip? You mentioned a portrait so I take you are using a custom battle system that displays the face of the actors? Which one?
lemonairable
It's an original made my somebody at savepoint:

The Code

CODE
#===========================================================
# ** Window_Portrait
#===========================================================
class Window_Portrait < Window_Base
  #-----------------------------------------------------------------------------
  # * Object Initialization
  #-----------------------------------------------------------------------------
  def initialize
    super(483, 0, 160, 170)
    self.contents = Bitmap.new(width - 32, height - 32)
  end
  #-----------------------------------------------------------------------------
  # * Draw Actor Graphic
  #-----------------------------------------------------------------------------
  def draw_actor_face_graphic(actor, x, y)
    bitmap = RPG::Cache.picture(actor.id.to_s)
    self.contents.blt(x, y, bitmap, Rect.new(0, 0, bitmap.width, bitmap.height))
  end
  #-----------------------------------------------------------------------------
  # * Refresh
  #-----------------------------------------------------------------------------
  def refresh(actor)
    self.contents.clear
    draw_actor_face_graphic(actor, 0, 0)
  end
end



There are also minor edits to Scene_Battle 1 and 3, detailed in MGC's second post here:
http://www.save-point.org/showthread.php?t...=22512#pid22512
Kread-EX
Tough luck: it's not a sprite but a window so the method to draw the flipped graphic will indeed be the slow one. So I'll give you two options: flipping with script (slow) or switching to another file flipped with an image editing program.

In the first code MGC gave you (Window_Portrait), modify the refresh method like this:

CODE
  #-----------------------------------------------------------------------------
  # * Refresh
  #-----------------------------------------------------------------------------
  def refresh(actor, flip = false)
    self.contents.clear
    draw_actor_face_graphic(actor, 0, 0, flip)
  end

Then modify draw_actor_face_graphic like this:
CODE
  #-----------------------------------------------------------------------------
  # * Draw Actor Graphic
  #-----------------------------------------------------------------------------
  def draw_actor_face_graphic(actor, x, y, flip)
    bitmap = RPG::Cache.picture(actor.id.to_s)
    flipped_bitmap = Bitmap.new(bitmap.width, bitmap.height)
    rect = Rect.new(0, 0, 1, height)
    if flip
      bitmap.width.times do |i|
       rect.x = bitmap.width - 1 - i
       flipped.blt(i, 0, bitmap, flip_rect)
      end
      self.contents.blt(x, y, bitmap, Rect.new(0, 0, flipped.width, flipped.height))
    else
      self.contents.blt(x, y, bitmap, Rect.new(0, 0, flipped.width, flipped.height))
    end
  end

Now, in the 3rd piece of code MGC gave you, look at this:
CODE
    # refresh the portrait
    @window_portrait.visible = true
    @window_portrait.refresh(@active_battler)

Setup the conditions for the flip (I don't know what they are so I can't do it) and to activate it, simply replace @window_portrait.refresh(@active_battler) with @window_portrait.refresh(@active_battler, true) and this is it.

In the event you want to use flipped pictures rather than flipping them with the script (and you should), use the same syntax than before for your file and simply add _flipped at the end. Then, modify draw_actor_face_graphic like this:
CODE
#-----------------------------------------------------------------------------
  # * Draw Actor Graphic
  #-----------------------------------------------------------------------------
  def draw_actor_face_graphic(actor, x, y, flip)
    bitmap = RPG::Cache.picture(actor.id.to_s + '_flipped')
    self.contents.blt(x, y, bitmap, Rect.new(0, 0, flipped.width, flipped.height))
  end
lemonairable
Thank you. This was the last thing I needed to complete my custom battle system.
Redd
Why not just flip it around in paint?
lemonairable
@Redd: They have to be facing right at one point and left at another.

@Kread_EX: Slight problem with this portion of the script:
CODE
#-----------------------------------------------------------------------------
  # * Draw Actor Graphic
  #-----------------------------------------------------------------------------
  def draw_actor_face_graphic(actor, x, y, flip)
    bitmap = RPG::Cache.picture(actor.id.to_s + '_flipped')
    self.contents.blt(x, y, bitmap, Rect.new(0, 0, flipped.width, flipped.height))
  end


I'm getting "wrong number of arguments (3 for 4)" on the line after the note. I believe it is the (actor, x, y, flip) that is causing the problem.
Kread-EX
Did you add the flip to refresh? Like this:
CODE
  #-----------------------------------------------------------------------------
  # * Refresh
  #-----------------------------------------------------------------------------
  def refresh(actor, flip = false)
    self.contents.clear
    draw_actor_face_graphic(actor, 0, 0, flip)
  end

You can see I added it to draw_actor_face_graphic here too. The error happens because it's probably not added here.
lemonairable
Oh, nevermind. All I had to do was add an extra "end."
Redd
So all you would have to do is make two copies of the image, one facing right and one facing left, right?

Or am I totally missing something here?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.