Class: RubySketch::Pin

Inherits:
Object
  • Object
show all
Defined in:
lib/rubysketch/pin.rb

Overview

A pin fastened at a point on a sprite. Creating a constraint between sprites starts from a pin.

Instance Method Summary collapse

Instance Method Details

#chase(*args, **options, &block) ⇒ ChaseConstraint

Creates a constraint that moves the pin toward the target every frame.

Parameters:

  • target (Sprite, Pin, Vector, Array<Numeric>, nil)

    the center of a sprite, a pin, or a point in the world. chases nothing when target is omitted

Returns:



65
66
67
# File 'lib/rubysketch/pin.rb', line 65

def chase(*args, **options, &block)
  create__ ChaseConstraint, @pin__.chase(*unwrap__(args)), options, block
end

Creates a constraint that keeps the distance to the target point.

Parameters:

  • target (Sprite, Pin, Vector, Array<Numeric>, nil)

    the center of a sprite, a pin, or a point in the world. links to the world when target is omitted

Returns:



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

def link(*args, **options, &block)
  create__ LinkConstraint, @pin__.link(*unwrap__(args)), options, block
end

#positionVector? Also known as: pos

Returns the position of the pin.

Returns:

  • (Vector, nil)

    sprite-local position, or nil for the center



81
82
83
# File 'lib/rubysketch/pin.rb', line 81

def position()
  @pin__.position&.toVector
end

#snap(*args, **options, &block) ⇒ SnapConstraint

Creates a constraint that makes the pin and the target point coincide.

Parameters:

  • target (Sprite, Pin, Vector, Array<Numeric>, nil)

    the center of a sprite, a pin, or a point in the world. snaps to the world when target is omitted

Returns:



28
29
30
# File 'lib/rubysketch/pin.rb', line 28

def snap(*args, **options, &block)
  create__ SnapConstraint, @pin__.snap(*unwrap__(args)), options, block
end

#spriteSprite?

Returns the sprite the pin is fastened to.

Returns:

  • (Sprite, nil)

    nil for a pin in the world



73
74
75
# File 'lib/rubysketch/pin.rb', line 73

def sprite()
  @sprite__
end

#wheel(*args, **options, &block) ⇒ WheelConstraint

Creates a constraint that makes the pin ride on the target like a wheel: it slides along an axis for the suspension and spins freely.

Parameters:

  • target (Sprite, Pin, Vector, Array<Numeric>, nil)

    the center of a sprite, a pin, or a point in the world. rides on the world when target is omitted

Returns:



53
54
55
# File 'lib/rubysketch/pin.rb', line 53

def wheel(*args, **options, &block)
  create__ WheelConstraint, @pin__.wheel(*unwrap__(args)), options, block
end