Event becomes 'Jitterish'

● ARCHIVED · READ-ONLY
Started by Napoleon 1 posts View original ↗
  1. Happens when the event that is being followed moves really fast. It becomes 'jiterish' or it even seems to disappear sometimes. I tested it on a NPC with random-movement + high frequency + 8x movespeed.

    Problem code:

    alias nap_cam_scroll_update update def update(main = false) if $game_system.camera_target set_display_pos($game_map.events[$game_system.camera_target].real_x - ((Graphics.width / 2) / 32), $game_map.events[$game_system.camera_target].real_y - ((Graphics.height / 2) / 32)) end nap_cam_scroll_update(main) endI tried moving the code to the game_character class instead but that didn't work either. Besides, it makes no sense. I center the camera location on the event every single frame. And yet it's not good enough? I also checked if I might be using fixnums instead of floats but nope. It's all good.

    $game_map.set_display_pos() should be the right method.

    Full code (be aware of long code snippet :p ):

    Spoiler
    Code:
    #sb:cam_scroll [field]=begin#===============================================================================Napoleons Camera ScrollVersion 1.00By NapoleonAbout:- Allows you to scroll the camera to a specific location or event (including  following an event).- Scrolling can be done instantly or over time.Instructions:- Place below "▼ Materials" but above "▼ Main Process".- Note that it always tries to center the camera on the target. Unless it's near  the edge of a non-looping map of course.- Create a script call and use the following command(s) as you see fit:scroll_to(x, y, velocity=4)scroll_to_ev(event_id, velocity=4)reset_scroll(velocity=4) # Reset camera scrollreset_scroll_instantcamera_target(event_id=nil)# Examples:scroll_to(10, 11, 3)scroll_to_ev(3) # Scroll to event with id 3.reset_scroll(2)camera_target(4) # follows event with id 4camera_target() # follows the player again  Requires:- RPG Maker VX AceKnown issues:- It jitters when following events (especially fast-moving events)Terms of Use:- This work is licensed under the Creative Commons Attribution 4.0 International  License. To view a copy of this license, visit  [URL="http://creativecommons.org/licenses/by/4.0/deed.en_US.-"]http://creativecommons.org/licenses/by/4.0/deed.en_US.-[/URL] Attribution is not required. This overrules what's stated in the above  license.  Version History:0.90 (03 August 2014)  - First Release=end#===============================================================================# Settings#===============================================================================module Nap; module Cam_Scroll  # Set to true to automatically clear the camera-target when switching maps.  # Note: if you switch maps and the camera is set to an event with an id that  #       does not exist on the new map then this script will crash. That's why  #       I added this setting.  AUTO_RESET_CAMERA_TARGET = falseend; end$imported ||= {}$imported[:nap_cam_scroll] = 0.90#===============================================================================# Module Nap#===============================================================================module Nap  N  = 8  NE = 9  E  = 6  SE = 3  S  = 2  SW = 1  W  = 4  NW = 7end#===============================================================================# Game Player#===============================================================================if Nap::Cam_Scroll::AUTO_RESET_CAMERA_TARGET  class Game_Player < Game_Character    #-----------------------------------------------------------------------------    # Reserve Transfer                                                     [ALIAS]    #-----------------------------------------------------------------------------    alias nap_cam_scroll_reserve_transfer reserve_transfer    def reserve_transfer(map_id, x, y, d = 2)      nap_cam_scroll_reserve_transfer(map_id, x, y, d)      $game_system.camera_target = nil    end  endend#===============================================================================# Game System#===============================================================================class Game_System  attr_accessor :camera_target # This accessor is automatically saved&loaded because it resides in $game_system.  #-----------------------------------------------------------------------------  # Initialize                                                           [ALIAS]  #-----------------------------------------------------------------------------  alias nap_cam_scroll_initialize initialize  def initialize    @camera_target = nil    nap_cam_scroll_initialize  endend#===============================================================================# Game Map#===============================================================================class Game_Map  #-----------------------------------------------------------------------------  # Nap Get Scroll Direction Step                                          [NEW]  #-----------------------------------------------------------------------------  def nap_get_scroll_direction_step(target_x, target_y)    # The width and height offsets make sure that the camera centers the target location instead of putting it in the lower left corner.    w = (Graphics.width / 2) / 32    h = (Graphics.height / 2) / 32        x = @display_x + w    y = @display_y + h        # North    if target_x == x && target_y < y      return Nap::N    # North East    elsif target_x > x && target_y < y      if can_scroll?(Nap::NE)        return Nap::NE      elsif can_scroll?(Nap::N)        return Nap::N      else        return Nap::E      end    # East    elsif target_x > x && target_y == y      return Nap::E    # South East    elsif target_x > x && target_y > y      if can_scroll?(Nap::SE)        return Nap::SE      elsif can_scroll?(Nap::S)        return Nap::S      else        return Nap::E      end    # South    elsif target_x == x && target_y > y      return Nap::S    # South West    elsif target_x < x && target_y > y      if can_scroll?(Nap::SW)        return Nap::SW      elsif can_scroll?(Nap::S)        return Nap::S      else        return Nap::W      end    # West    elsif target_x < x && target_y == y      return Nap::W    # North West    elsif target_x < x && target_y < y      if can_scroll?(Nap::NW)        return Nap::NW      elsif can_scroll?(Nap::N)        return Nap::N      else        return Nap::W      end    end    return nil # return nil if the target equals the current camera location  end  #-----------------------------------------------------------------------------  # Scroll To                                                              [NEW]  #-----------------------------------------------------------------------------  def scroll_to(target_x, target_y, velocity=1)    return if $game_party.in_battle    w = (Graphics.width / 2) / 32    h = (Graphics.height / 2) / 32    loop {      direction = nap_get_scroll_direction_step(target_x, target_y)      return if !direction # return and do nothing if the target equals the current camera location      return if !can_scroll?(direction) # return if further scrolling to the destination is not possible      start_scroll(direction, 1, velocity)      Fiber.yield while $game_map.scrolling?      return if display_x == (target_x - w) && display_y == (target_y - h)    }  end  #-----------------------------------------------------------------------------  # Do Scroll                                                        [OVERWRITE]  #-----------------------------------------------------------------------------  def do_scroll(direction, distance)    case direction    when Nap::N # Up      scroll_up(distance)    when Nap::NE # Upper Right      scroll_up(distance); scroll_right(distance)    when Nap::E # Right      scroll_right(distance)    when Nap::SE      scroll_down(distance); scroll_right(distance)    when Nap::S      scroll_down(distance)    when Nap::SW      scroll_down(distance); scroll_left(distance)    when Nap::W      scroll_left(distance)    when Nap::NW      scroll_up(distance); scroll_left(distance)    else      raise "Invalid scroll-direction for Game_Map.do_scroll(#{direction}, #{distance})"    end  end  #-----------------------------------------------------------------------------  # Can Scroll?                                                            [NEW]  # Returns wether or not the map can be scrolled towards that direction.  # Takes map-loopings into accounts.  #-----------------------------------------------------------------------------  def can_scroll?(direction)    w = Graphics.width / 32    h = Graphics.height / 32        case direction    when Nap::N # Up      @display_y > 0 || loop_vertical?    when Nap::NE # Upper Right      ((@display_x < width + w) && (@display_y > 0)) || (loop_vertical? && loop_horizontal?)    when Nap::E # Right      (@display_x < width + w) || loop_horizontal?    when Nap::SE      ((@display_x < width + w) && (@display_y < height + h)) || (loop_vertical? && loop_horizontal?)    when Nap::S      (@display_y < height + h) || loop_vertical?    when Nap::SW      ((@display_x > 0) && (@display_y < height + h)) || (loop_vertical? && loop_horizontal?)    when Nap::W      (@display_x > 0) || loop_horizontal?    when Nap::NW      ((@display_x > 0) && (@display_y > 0)) || (loop_vertical? && loop_horizontal?)    else      raise "Invalid scroll-direction for Game_Map.can_scroll?(#{direction})"    end  end  #-----------------------------------------------------------------------------  # Update                                                               [ALIAS]  #-----------------------------------------------------------------------------  alias nap_cam_scroll_update update  def update(main = false)    if $game_system.camera_target      set_display_pos($game_map.events[$game_system.camera_target].real_x - ((Graphics.width  / 2) / 32),                      $game_map.events[$game_system.camera_target].real_y - ((Graphics.height / 2) / 32))    end    nap_cam_scroll_update(main)  endend#===============================================================================# Game Interpreter#===============================================================================class Game_Interpreter  #-----------------------------------------------------------------------------  # Camera Target  # use a nil value to reset it back to the player. Example: camera_target()  #-----------------------------------------------------------------------------  def camera_target(ev_id=nil)    if ev_id      $game_system.camera_target = ev_id    else      reset_camera_target    end  end  #-----------------------------------------------------------------------------  # Camera Target  # For: Resets the camera target. Same as calling camera_target() without any  #      parameters or a nil value.  #-----------------------------------------------------------------------------  def reset_camera_target    $game_system.camera_target = nil    reset_scroll_instant  end  #-----------------------------------------------------------------------------  # Rest Scroll  # For: Resets the camera back to the player's location  #-----------------------------------------------------------------------------  def reset_scroll(velocity=4)    scroll_to($game_player.x, $game_player.y, velocity)  end  #-----------------------------------------------------------------------------  # Reset Scroll Instant  # For: Instantly resets the camera scroll  #-----------------------------------------------------------------------------  def reset_scroll_instant    $game_map.set_display_pos($game_player.real_x - ((Graphics.width  / 2) / 32),                              $game_player.real_y - ((Graphics.height / 2) / 32))  end  #-----------------------------------------------------------------------------  # Scroll To  # Velocity: 1=8x slower, 2=4x slower, 3=2x slower, 4=normal, 5=2x faster, 6-4x faster  #-----------------------------------------------------------------------------  def scroll_to(x, y, velocity=4)    raise "scroll_to() requires a velocity within the 1-6 range. Velocity given was: #{velocity}" if !velocity.between?(1,6)    $game_map.scroll_to(x, y, velocity)  end  #-----------------------------------------------------------------------------  # Scroll To Event  #-----------------------------------------------------------------------------  def scroll_to_ev(ev_id, velocity=4)    raise "scroll_to() requires a velocity within the 1-6 range. Velocity given was: #{velocity}" if !velocity.between?(1,6)    $game_map.scroll_to($game_map.events[ev_id].real_x - ((Graphics.width  / 2) / 32),                        $game_map.events[ev_id].real_y - ((Graphics.height / 2) / 32),                        velocity)  endend # class Game_Interpreter#===============================================================================