[XP] Locking Pictures

Started by KK20, February 09, 2015, 07:42:24 pm

Previous topic - Next topic

KK20

Locking Pictures
Authors: KK20
Version: 1.0
Type: Picture Add-on
Key Term: Environment Add-on



Introduction

When using the 'Show Picture' event command, pictures are always displayed as if stuck to the screen. No matter how much the player moves around, they can never escape the clutches of the picture.

With this script, you can "lock" pictures into place. As the screen moves, the picture will move along with it, eventually sliding off-screen.


Features


  • Lock pictures into place! They won't follow you around anymore.

  • Need them unlocked again? No problem.

  • Plug-n-play; very easy to use




Screenshots

Spoiler: ShowHide



Demo

None


Script

Spoiler: ShowHide

=begin
================================================================================
Locking Pictures                                                    Ver 1.0
by KK20                                                             Feb 9 2015
________________________________________________________________________________
[ Introduction ]

When using the 'Show Picture' event command, pictures are always displayed as
if stuck to the screen. No matter how much the player moves around, they can
never escape the clutches of the picture.

With this script, you can "lock" pictures into place. As the screen moves, the
picture will move along with it, eventually sliding off-screen.

________________________________________________________________________________
[ Instructions ]

Place script below Scene_Debug, above Main (you know the drill by now).

To lock a picture in its place, use a 'Script' event command and put:
                        lock_picture(ID)
where ID is the picture number you want to lock into place. Alternatively, you
can omit the (ID) altogether, like so:
                        lock_picture
When using 'Show Picture' or 'Move Picture', the last picture ID you used will
now be locked. It's mainly just for convenience.

To unlock the picture, use:
                        unlock_picture(ID)
Again, you can omit the (ID) as this will unlock the last picture modified.

________________________________________________________________________________
[ Compatibility ]

Should be none. Aliases Game_Picture methods for optimal compatibility.

________________________________________________________________________________
[ Credits ]

KK20 - for the script

================================================================================
=end

#=============================================================================
# ** Interpreter
#=============================================================================
class Interpreter
  #--------------------------------------------------------------------------
  # * Show Picture
  #--------------------------------------------------------------------------
  alias remember_last_picture_id_show command_231
  def command_231
    # Get picture number
    @last_pic_number = @parameters[0] + ($game_temp.in_battle ? 50 : 0)
    return remember_last_picture_id_show
  end
  #--------------------------------------------------------------------------
  # * Move Picture
  #--------------------------------------------------------------------------
  alias remember_last_picture_id_move command_232
  def command_232
    # Get picture number
    @last_pic_number = @parameters[0] + ($game_temp.in_battle ? 50 : 0)
    return remember_last_picture_id_move
  end
  #--------------------------------------------------------------------------
  # * Lock Picture
  # - Locks the picture at ID in place. The picture can now move off screen.
  #--------------------------------------------------------------------------
  def lock_picture(id = @last_pic_number)
    return false if id.nil?
    $game_screen.pictures[id].lock = true
    return true
  end
  #--------------------------------------------------------------------------
  # * Unlock Picture
  # - Unlocks the picture at ID. The picture now moves with the player/screen.
  #--------------------------------------------------------------------------
  def unlock_picture(id = @last_pic_number)
    return if id.nil?
    $game_screen.pictures[id].lock = false
    return true
  end
end
#=============================================================================
# ** Game_Picture
#=============================================================================
class Game_Picture
  attr_accessor :lock
  #--------------------------------------------------------------------------
  # * Set Lock
  # - Locks/Unlocks the picture
  #--------------------------------------------------------------------------
  def lock=(lock)
    @lock = lock
    if lock
      @base_x = @x
      @base_y = @y
    end
  end
  #--------------------------------------------------------------------------
  # * Show Picture
  # - Sets base coordinates if the picture was set to lock prior to showing
  #--------------------------------------------------------------------------
  alias new_showtarget_if_locked show
  def show(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
    new_showtarget_if_locked(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
    if @lock
      @base_x = @x
      @base_y = @y
    end
  end
  #--------------------------------------------------------------------------
  # * Move Picture
  # - Sets new target location if picture is locked
  #--------------------------------------------------------------------------
  alias new_movetarget_if_locked move
  def move(duration, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
    new_movetarget_if_locked(duration, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
    if @lock
      @target_x = x.to_f - $game_map.display_x / 4
      @target_y = y.to_f - $game_map.display_y / 4
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  alias lock_and_unlock_picture update
  def update
    # If 'Move Picture' is in effect on a locked picture
    fix_position = @duration >= 1 && @lock
    # Call alias
    lock_and_unlock_picture
    # 'Move Picture' needs to move base coordinates, not actual
    if fix_position
      d = @duration + 1
      @base_x = (@base_x * (d - 1) + @target_x) / d
      @base_y = (@base_y * (d - 1) + @target_y) / d
    end
    # Modify actual coordinates if locked
    if @lock
      @x = @base_x - $game_map.display_x / 4
      @y = @base_y - $game_map.display_y / 4
    end
  end
end




Instructions

In script.
Commands are
lock_picture(ID)
unlock_picture(ID)



Compatibility

Should be none at all. There are very few scripts that modify Game_Picture, so you should be good to go. If you by chance do have a script that makes changes to Game_Pictures, place this script below it.


Credits and Thanks


  • KK20 - for the script




Author's Notes

Remember to unlock your pictures, especially if reusing an ID on the same map.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!