Class: Box2D::Chain
Constant Summary
collapse
- ID_CLASS =
Native::ChainId
Instance Attribute Summary collapse
Attributes inherited from Handle
#id, #world
Instance Method Summary
collapse
Methods inherited from Handle
#destroyed?, #eql?, #hash, #valid?
Constructor Details
#initialize(world, id, body: nil) ⇒ Chain
Returns a new instance of Chain.
9
10
11
12
|
# File 'lib/box2d/chain.rb', line 9
def initialize(world, id, body: nil)
super(world, id)
@body = body
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
7
8
9
|
# File 'lib/box2d/chain.rb', line 7
def body
@body
end
|
Instance Method Details
#destroy ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/box2d/chain.rb', line 14
def destroy
ensure_valid!
Native.b2DestroyChain(@id)
invalidate!
@world.unregister_chain(self)
@body&.unregister_chain(self)
true
end
|
#friction ⇒ Object
35
36
37
38
|
# File 'lib/box2d/chain.rb', line 35
def friction
ensure_valid!
Native.b2Chain_GetFriction(@id)
end
|
#friction=(value) ⇒ Object
#restitution ⇒ Object
45
46
47
48
|
# File 'lib/box2d/chain.rb', line 45
def restitution
ensure_valid!
Native.b2Chain_GetRestitution(@id)
end
|
#restitution=(value) ⇒ Object
50
51
52
53
|
# File 'lib/box2d/chain.rb', line 50
def restitution=(value)
ensure_valid!
Native.b2Chain_SetRestitution(@id, ShapeDefinition.coefficient(value, "restitution"))
end
|
#segments ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/box2d/chain.rb', line 23
def segments
ensure_valid!
count = Native.b2Chain_GetSegmentCount(@id)
pointer = FFI::MemoryPointer.new(Native::ShapeId, count)
actual = Native.b2Chain_GetSegments(@id, pointer, count)
Array.new(actual) do |index|
id = Native::ShapeId.new(pointer + index * Native::ShapeId.size)
@world.shape_for_id(id)
end
end
|