Module: Moon::Transitionable

Includes:
TransitionHost
Included in:
CameraBase, RenderContext
Defined in:
lib/moon/packages/std/mixins/transitionable.rb

Instance Method Summary collapse

Methods included from TransitionHost

#add_transition, #finish_transitions, #remove_transition, #update_transitions

Instance Method Details

#key_transition(attribute, value, duration) ⇒ Transition

Add a keyed transition

A keyed transition will only have 1 active transition per attribute
However multiple transitions can still operate on the attribute if
they where not keyed.

Parameters:

  • attribute (String)

    @example “color” @example “position.x”

  • value (Object)

    target value

  • duration (Numeric)

    in seconds

Returns:


33
34
35
36
37
38
39
40
41
42
# File 'lib/moon/packages/std/mixins/transitionable.rb', line 33

def key_transition(attribute, value, duration)
  @key_transition ||= {}
  if @key_transition.key?(attribute)
    remove_transition(@key_transition[attribute])
  end
  key = attribute
  t = @key_transition[key] = transition(attribute, value, duration)
  t.key = key
  t
end

#remove_transitions(transitions) ⇒ Void

Parameters:

  • transitions (Array<Transitions>)

Returns:

  • (Void)

46
47
48
49
50
51
# File 'lib/moon/packages/std/mixins/transitionable.rb', line 46

def remove_transitions(transitions)
  if @key_transition
    transitions.each { |t| @key_transition.delete(t.key) if t.key }
  end
  super
end

#transition(attribute, value, duration, easer = nil) ⇒ Transition

Parameters:

  • attribute (String)

    @example “color” @example “position.x”

  • value (Object)

    target value

  • duration (Numeric)

    in seconds

Returns:


14
15
16
17
18
19
20
21
# File 'lib/moon/packages/std/mixins/transitionable.rb', line 14

def transition(attribute, value, duration, easer = nil)
  easer ||= Easing::Linear
  src = dotsend(attribute)
  setter = "#{attribute}="
  add_transition(src, value, duration, easer) do |v|
    dotsend(setter, v)
  end
end