Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Commit

Permalink
[#176] Adding support for easing during scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
acs-l committed Aug 26, 2017
1 parent f85f3d3 commit 493ab3d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2914,9 +2914,9 @@ def camera_scroll(direction, distance, speed)
$game_map.start_scroll(direction, distance, speed)
end

def camera_scroll_towards(x, y, nb_steps)
def camera_scroll_towards(x, y, nb_steps, easing = :InLinear)
Fiber.yield while $game_map.scrolling?
$game_map.start_scroll_towards(x, y, nb_steps)
$game_map.start_scroll_towards(x, y, nb_steps, Easing::FUNCTIONS[easing])
end

def camera_move_on(x, y)
Expand Down
4 changes: 2 additions & 2 deletions src/Doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module Doc
:undocumented => "Commandes non documentées",
:orphans => "Commandes inconnues",
:suggest => "Suggestion",
:ease_desc => "Fonction à utiliser pour effectuer la transition. :linear par défaut."
:ease_desc => "Fonction à utiliser pour effectuer la transition. :InLinear par défaut."
}
documentation_add_link "GitHub", "https://github.com/RMEx/RME"
documentation_add_link "Manuel d'utilisation (Wiki)", "https://github.com/RMEx/RME/wiki"
Expand Down Expand Up @@ -5714,7 +5714,7 @@ module Command
:x => ["L'abscisse du point cible", :Fixnum],
:y => ["L'ordonnée du point cible", :Fixnum],
:nb_steps => ["Le nombre d'étapes lors du défilement (plus il y en a, plus le temps de défilement sera long)", :Fixnum]

:easing_function => []
}
register_command :camera,'Command.camera_scroll_towards'

Expand Down
18 changes: 11 additions & 7 deletions src/EvEx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2635,30 +2635,34 @@ def update_scroll
@display_x = target.x
@display_y = target.y
@scroll_rest -= 1

@scroll_function = nil if (0 >= @scroll_rest)
end
end
#--------------------------------------------------------------------------
# * Scroll straight towards the given point (x, y)
#--------------------------------------------------------------------------
def start_scroll_towards(x, y, nb_steps)
def start_scroll_towards(x, y, nb_steps, easing_function)
initial_point = Point.new(@display_x, @display_y)
targeted_point = Point.new(x, y)

return if initial_point.eql? targeted_point

delta_x = (targeted_point.x - initial_point.x).abs / nb_steps
delta_x = -delta_x if targeted_point.x < initial_point.x
nb_steps += 1

linear_interpolant = Point.linear_interpolant(initial_point, targeted_point)

linear_variation = lambda { |i| initial_point.x + i * delta_x }
direction = (targeted_point.x < initial_point.x) ? -1 : 1
distance = (initial_point.x - targeted_point.x).abs
x_step_variation = Easing.tween(0, distance, nb_steps, easing_function)
x_variation = lambda do |i|
initial_point.x + direction * x_step_variation.call(i)
end

@scroll_function = lambda do |nb_steps_still|
return targeted_point if (0 >= nb_steps_still)
return targeted_point if (1 >= nb_steps_still)

i = nb_steps - nb_steps_still
x = linear_variation.call(i)
x = x_variation.call(i)
y = linear_interpolant.call(x)

Point.new(x % @map.width, y % @map.height)
Expand Down

0 comments on commit 493ab3d

Please sign in to comment.