Class: RubySketch::Constraint

Inherits:
Object
  • Object
show all
Includes:
Xot::Setter
Defined in:
lib/rubysketch/constraint.rb

Overview

Constrains the motion of sprites. Constraints are created with Sprite#snap, #link, #wheel and #chase (or the same verbs on Sprite#pin), not with new.

Instance Method Summary collapse

Instance Method Details

#active?Boolean

Returns whether the constraint is active in a physics world.

Returns:

  • (Boolean)

    active or not



106
107
108
# File 'lib/rubysketch/constraint.rb', line 106

def active?()
  @constraint__.active?
end

#collide=(bool) ⇒ Boolean

Sets whether the constrained sprites collide with each other.

Parameters:

  • bool (Boolean)

    collide or not

Returns:

  • (Boolean)

    collide or not



68
69
70
# File 'lib/rubysketch/constraint.rb', line 68

def collide=(bool)
  @constraint__.collide = bool
end

#collide?Boolean

Returns whether the constrained sprites collide with each other.

Returns:

  • (Boolean)

    collide or not



76
77
78
# File 'lib/rubysketch/constraint.rb', line 76

def collide?()
  @constraint__.collide?
end

#dampingNumeric

Returns the spring damping ratio.

Returns:

  • (Numeric)

    damping ratio



58
59
60
# File 'lib/rubysketch/constraint.rb', line 58

def damping()
  @constraint__.damping
end

#damping=(ratio) ⇒ Numeric

Sets the spring damping ratio.

Parameters:

  • ratio (Numeric)

    0 (no damping) to 1 (critical damping)

Returns:

  • (Numeric)

    damping ratio



50
51
52
# File 'lib/rubysketch/constraint.rb', line 50

def damping=(ratio)
  @constraint__.damping = ratio
end

#forceNumeric?

Returns the maximum force that drives the constraint.

Returns:

  • (Numeric, nil)

    force, or nil for the default strength



96
97
98
# File 'lib/rubysketch/constraint.rb', line 96

def force()
  @constraint__.force
end

#force=(force) ⇒ Numeric?

Sets the maximum force (or torque) that drives the constraint.

Parameters:

  • force (Numeric, nil)

    maximum force, or nil for the default strength. 0 makes the drive powerless

Returns:

  • (Numeric, nil)

    force



88
89
90
# File 'lib/rubysketch/constraint.rb', line 88

def force=(force)
  @constraint__.force = force
end

#removeConstraint

Removes the constraint permanently.

Returns:



21
22
23
24
# File 'lib/rubysketch/constraint.rb', line 21

def remove()
  @constraint__.remove
  self
end

#removed?Boolean

Returns whether the constraint was removed.

Returns:

  • (Boolean)

    removed or not



114
115
116
# File 'lib/rubysketch/constraint.rb', line 114

def removed?()
  @constraint__.removed?
end

#springNumeric?

Returns the spring stiffness in hertz.

Returns:

  • (Numeric, nil)

    hertz, or nil if the constraint is rigid



40
41
42
# File 'lib/rubysketch/constraint.rb', line 40

def spring()
  @constraint__.spring
end

#spring=(hertz) ⇒ Numeric?

Sets the spring stiffness in hertz.

Parameters:

  • hertz (Numeric, nil)

    stiffness, or nil to make it rigid

Returns:

  • (Numeric, nil)

    hertz



32
33
34
# File 'lib/rubysketch/constraint.rb', line 32

def spring=(hertz)
  @constraint__.spring = hertz
end

#spritesArray<Sprite, nil>

Returns the sprites the constraint is fastened to.

Returns:

  • (Array<Sprite, nil>)

    nil for a world anchor



122
123
124
# File 'lib/rubysketch/constraint.rb', line 122

def sprites()
  @sprites__ ||= @constraint__.views.map {_1&.sprite}.freeze
end