Class: RubySketch::Constraint
- Inherits:
-
Object
- Object
- RubySketch::Constraint
- 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.
Direct Known Subclasses
ChaseConstraint, LinkConstraint, SnapConstraint, WheelConstraint
Instance Method Summary collapse
-
#active? ⇒ Boolean
Returns whether the constraint is active in a physics world.
-
#collide=(bool) ⇒ Boolean
Sets whether the constrained sprites collide with each other.
-
#collide? ⇒ Boolean
Returns whether the constrained sprites collide with each other.
-
#damping ⇒ Numeric
Returns the spring damping ratio.
-
#damping=(ratio) ⇒ Numeric
Sets the spring damping ratio.
-
#force ⇒ Numeric?
Returns the maximum force that drives the constraint.
-
#force=(force) ⇒ Numeric?
Sets the maximum force (or torque) that drives the constraint.
-
#remove ⇒ Constraint
Removes the constraint permanently.
-
#removed? ⇒ Boolean
Returns whether the constraint was removed.
-
#spring ⇒ Numeric?
Returns the spring stiffness in hertz.
-
#spring=(hertz) ⇒ Numeric?
Sets the spring stiffness in hertz.
-
#sprites ⇒ Array<Sprite, nil>
Returns the sprites the constraint is fastened to.
Instance Method Details
#active? ⇒ Boolean
Returns whether the constraint is active in a physics world.
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.
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.
76 77 78 |
# File 'lib/rubysketch/constraint.rb', line 76 def collide?() @constraint__.collide? end |
#damping ⇒ Numeric
Returns the spring 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.
50 51 52 |
# File 'lib/rubysketch/constraint.rb', line 50 def damping=(ratio) @constraint__.damping = ratio end |
#force ⇒ Numeric?
Returns the maximum force that drives the constraint.
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.
88 89 90 |
# File 'lib/rubysketch/constraint.rb', line 88 def force=(force) @constraint__.force = force end |
#remove ⇒ Constraint
Removes the constraint permanently.
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.
114 115 116 |
# File 'lib/rubysketch/constraint.rb', line 114 def removed?() @constraint__.removed? end |
#spring ⇒ Numeric?
Returns the spring stiffness in hertz.
40 41 42 |
# File 'lib/rubysketch/constraint.rb', line 40 def spring() @constraint__.spring end |
#spring=(hertz) ⇒ Numeric?
Sets the spring stiffness in hertz.
32 33 34 |
# File 'lib/rubysketch/constraint.rb', line 32 def spring=(hertz) @constraint__.spring = hertz end |
#sprites ⇒ Array<Sprite, nil>
Returns the sprites the constraint is fastened to.
122 123 124 |
# File 'lib/rubysketch/constraint.rb', line 122 def sprites() @sprites__ ||= @constraint__.views.map {_1&.sprite}.freeze end |