Package net.dermetfan.gdx.physics.box2d
Class Chain
java.lang.Object
net.dermetfan.gdx.physics.box2d.Chain
public class Chain
extends java.lang.Object
Holds
segments
and connections
to simulate a chain. Also provides modification methods that use a Chain.Builder
.-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Chain.Builder
used by aChain
to modify itstatic class
Chain.Connection
holds one or morejoints
static class
Chain.CopyBuilder
static class
Chain.DefBuilder
static class
Chain.DefShapeBuilder
static class
Chain.JointDefCopyBuilder
aChain.CopyBuilder
that uses aJointDef
inChain.JointDefCopyBuilder.createConnection(Body, int, Body, int)
-
Constructor Summary
Constructors Constructor Description Chain(int length, Chain.Builder builder)
creates a new Chain andbuilds
it to the givenlength
Chain(int length, Chain.Builder builder, boolean build)
Chain(Chain other)
creates a shallow copy of the givenChain
instanceChain(Chain.Builder builder)
Chain(Chain.Builder builder, com.badlogic.gdx.physics.box2d.Body... segments)
creates a new Chain with the givensegments
-
Method Summary
Modifier and Type Method Description void
add(com.badlogic.gdx.physics.box2d.Body segment)
adds
the givensegment
to the end of this Chainvoid
add(com.badlogic.gdx.physics.box2d.Body... segments)
adds
the given segments to the end of this ChainChain.Connection
createConnection(int segmentIndex1, int segmentIndex2)
creates
a newChain.Connection
Chain.Connection
createConnection(int segmentIndex1, int segmentIndex2, Chain.Builder builder)
Creates aChain.Connection
using theChain.Builder
passing the correct parameters toChain.Builder.createConnection(Body, int, Body, int)
specified by the given indices.com.badlogic.gdx.physics.box2d.Body
createSegment(int index)
creates
a segment for the given index using thebuilder
com.badlogic.gdx.physics.box2d.Body
createSegment(int index, Chain.Builder builder)
Creates asegment
using the givenChain.Builder
passing the correct parameters toChain.Builder.createSegment(int, int, Chain)
specified by the givenindex
.void
destroy(int index)
void
destroy(int beginIndex, int endIndex)
destroys
all segments from beginIndex to endIndexvoid
destroy(com.badlogic.gdx.physics.box2d.Body segment)
com.badlogic.gdx.physics.box2d.Body
extend()
extends
this Chain using thebuilder
Chain
extend(int length)
Chain
extend(int length, Chain.Builder builder)
com.badlogic.gdx.physics.box2d.Body
extend(Chain.Builder builder)
Chain.Builder
getBuilder()
Chain.Connection
getConnection(int index)
com.badlogic.gdx.utils.Array<Chain.Connection>
getConnections()
Warning: The returned Array is used by other methods and may be modified unexpectedly.com.badlogic.gdx.physics.box2d.Body
getSegment(int index)
com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Body>
getSegments()
Warning: The returned Array is used by other methods and may be modified unexpectedly.com.badlogic.gdx.physics.box2d.Body
insert(int index)
void
insert(int index, com.badlogic.gdx.physics.box2d.Body segment)
inserts asegment
into this Chainint
length()
com.badlogic.gdx.physics.box2d.Body
remove(int index)
removes asegment
from this Chaincom.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Body>
remove(int beginIndex, int endIndex)
removes
all segmetns from beginIndex to endIndexcom.badlogic.gdx.physics.box2d.Body
remove(com.badlogic.gdx.physics.box2d.Body segment)
com.badlogic.gdx.physics.box2d.Body
replace(int index, com.badlogic.gdx.physics.box2d.Body segment)
void
setBuilder(Chain.Builder builder)
void
shorten()
destorys
the last segmentvoid
shorten(int length)
destroys
the given amount of segments from the end of the ChainChain
split(int connectionIndex)
splits this Chain at the given index and returns a new Chain consisting of thesegments
up to the givenindex
Chain
split(Chain.Connection connection)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Chain
creates a shallow copy of the givenChain
instance- Parameters:
other
- theChain
to copy
-
Chain
- Parameters:
builder
- thebuilder
-
Chain
creates a new Chain andbuilds
it to the givenlength
- Parameters:
length
- the desired length of this Chainbuilder
- thebuilder
- See Also:
Chain(int, Builder, boolean)
-
Chain
- Parameters:
length
- The desired length of this Chain. Will be ignored ifbuild
is false.builder
- thebuilder
build
- if this Chain should bebuild
to the givenlength
-
Chain
creates a new Chain with the givensegments
- Parameters:
builder
- thebuilder
segments
- thesegments
-
-
Method Details
-
extend
- See Also:
extend(int, Builder)
-
extend
- See Also:
extend(Builder)
-
extend
public com.badlogic.gdx.physics.box2d.Body extend()extends
this Chain using thebuilder
- See Also:
extend(Builder)
-
extend
-
shorten
public void shorten()destorys
the last segment -
shorten
public void shorten(int length)destroys
the given amount of segments from the end of the Chain -
createSegment
public com.badlogic.gdx.physics.box2d.Body createSegment(int index)creates
a segment for the given index using thebuilder
- See Also:
createSegment(int, Builder)
-
createSegment
Creates asegment
using the givenChain.Builder
passing the correct parameters toChain.Builder.createSegment(int, int, Chain)
specified by the givenindex
. Does NOT add it to this Chain. -
createConnection
creates
a newChain.Connection
- See Also:
createConnection(int, int, Builder)
-
createConnection
public Chain.Connection createConnection(int segmentIndex1, int segmentIndex2, Chain.Builder builder)Creates aChain.Connection
using theChain.Builder
passing the correct parameters toChain.Builder.createConnection(Body, int, Body, int)
specified by the given indices. Does NOT add it to this Chain. -
add
public void add(com.badlogic.gdx.physics.box2d.Body segment)adds
the givensegment
to the end of this Chain- Parameters:
segment
- thesegment
to add
-
add
public void add(com.badlogic.gdx.physics.box2d.Body... segments)adds
the given segments to the end of this Chain- See Also:
add(Body)
-
insert
public com.badlogic.gdx.physics.box2d.Body insert(int index)- See Also:
insert(int, Body)
-
insert
public void insert(int index, com.badlogic.gdx.physics.box2d.Body segment)inserts asegment
into this Chain- Parameters:
index
- theindex
at which to insert the givensegment
segment
- thesegment
to insert
-
replace
public com.badlogic.gdx.physics.box2d.Body replace(int index, com.badlogic.gdx.physics.box2d.Body segment)- Parameters:
index
- the index of the segment to replacesegment
- thesegment
to insert- Returns:
- the
segment
that was at the givenindex
previously
-
remove
public com.badlogic.gdx.physics.box2d.Body remove(com.badlogic.gdx.physics.box2d.Body segment)- Parameters:
segment
- TheBody
to remove. Must be asegment
of thisChain
.- Returns:
- the given
body
- See Also:
remove(int)
-
remove
public com.badlogic.gdx.physics.box2d.Body remove(int index)removes asegment
from this Chain- Parameters:
index
- the index of thesegment
to remove- Returns:
- the removed
segment
- See Also:
Array.removeIndex(int)
-
remove
public com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Body> remove(int beginIndex, int endIndex)removes
all segmetns from beginIndex to endIndex- Parameters:
beginIndex
- the first index to removeendIndex
- the last index to remove- Returns:
- an Array holding the removed segments
- See Also:
tmpSegments
-
destroy
public void destroy(com.badlogic.gdx.physics.box2d.Body segment)- Parameters:
segment
- thesegment
to destroy- See Also:
destroy(int)
-
destroy
public void destroy(int index)- Parameters:
index
- the index of thesegment
todestroy
- See Also:
remove(int)
-
destroy
public void destroy(int beginIndex, int endIndex)destroys
all segments from beginIndex to endIndex- Parameters:
beginIndex
- the first index to destroyendIndex
- the last index to destroy
-
split
- Parameters:
connection
- theChain.Connection
inconnections
to split- Returns:
- the new
Chain
- See Also:
split(int)
-
split
splits this Chain at the given index and returns a new Chain consisting of thesegments
up to the givenindex
- Parameters:
connectionIndex
- the index of theconnection
to destroy- Returns:
- a Chain consisting of the segments before the given index
-
length
public int length()- Returns:
- the amount of
segments
in this Chain - See Also:
Array.size
-
getSegment
public com.badlogic.gdx.physics.box2d.Body getSegment(int index)- Parameters:
index
- the index of the desired segment- Returns:
- the
segment
at the given index
-
getConnection
- Parameters:
index
- the index of the desiredJoint
- Returns:
- the
Joint
at the given index
-
getSegments
public com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Body> getSegments()Warning: The returned Array is used by other methods and may be modified unexpectedly. It's highly recommended toadd
its items to your own collection.- Returns:
- the
segments
- See Also:
tmpSegments
-
getConnections
Warning: The returned Array is used by other methods and may be modified unexpectedly. It's highly recommended toadd
its items to your own collection.- Returns:
- an Array representing the current state of
connections
- See Also:
tmpConnections
-
getBuilder
- Returns:
- the
builder
-
setBuilder
- Parameters:
builder
- thebuilder
to set
-