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 interfaceChain.Builderused by aChainto modify itstatic classChain.Connectionholds one or morejointsstatic classChain.CopyBuilderstatic classChain.DefBuilderstatic classChain.DefShapeBuilderstatic classChain.JointDefCopyBuilderaChain.CopyBuilderthat uses aJointDefinChain.JointDefCopyBuilder.createConnection(Body, int, Body, int) -
Constructor Summary
Constructors Constructor Description Chain(int length, Chain.Builder builder)creates a new Chain andbuildsit to the givenlengthChain(int length, Chain.Builder builder, boolean build)Chain(Chain other)creates a shallow copy of the givenChaininstanceChain(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 voidadd(com.badlogic.gdx.physics.box2d.Body segment)addsthe givensegmentto the end of this Chainvoidadd(com.badlogic.gdx.physics.box2d.Body... segments)addsthe given segments to the end of this ChainChain.ConnectioncreateConnection(int segmentIndex1, int segmentIndex2)createsa newChain.ConnectionChain.ConnectioncreateConnection(int segmentIndex1, int segmentIndex2, Chain.Builder builder)Creates aChain.Connectionusing theChain.Builderpassing the correct parameters toChain.Builder.createConnection(Body, int, Body, int)specified by the given indices.com.badlogic.gdx.physics.box2d.BodycreateSegment(int index)createsa segment for the given index using thebuildercom.badlogic.gdx.physics.box2d.BodycreateSegment(int index, Chain.Builder builder)Creates asegmentusing the givenChain.Builderpassing the correct parameters toChain.Builder.createSegment(int, int, Chain)specified by the givenindex.voiddestroy(int index)voiddestroy(int beginIndex, int endIndex)destroysall segments from beginIndex to endIndexvoiddestroy(com.badlogic.gdx.physics.box2d.Body segment)com.badlogic.gdx.physics.box2d.Bodyextend()extendsthis Chain using thebuilderChainextend(int length)Chainextend(int length, Chain.Builder builder)com.badlogic.gdx.physics.box2d.Bodyextend(Chain.Builder builder)Chain.BuildergetBuilder()Chain.ConnectiongetConnection(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.BodygetSegment(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.Bodyinsert(int index)voidinsert(int index, com.badlogic.gdx.physics.box2d.Body segment)inserts asegmentinto this Chainintlength()com.badlogic.gdx.physics.box2d.Bodyremove(int index)removes asegmentfrom this Chaincom.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Body>remove(int beginIndex, int endIndex)removesall segmetns from beginIndex to endIndexcom.badlogic.gdx.physics.box2d.Bodyremove(com.badlogic.gdx.physics.box2d.Body segment)com.badlogic.gdx.physics.box2d.Bodyreplace(int index, com.badlogic.gdx.physics.box2d.Body segment)voidsetBuilder(Chain.Builder builder)voidshorten()destorysthe last segmentvoidshorten(int length)destroysthe given amount of segments from the end of the ChainChainsplit(int connectionIndex)splits this Chain at the given index and returns a new Chain consisting of thesegmentsup to the givenindexChainsplit(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 givenChaininstance- Parameters:
other- theChainto copy
-
Chain
- Parameters:
builder- thebuilder
-
Chain
creates a new Chain andbuildsit 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 ifbuildis false.builder- thebuilderbuild- if this Chain should bebuildto the givenlength
-
Chain
creates a new Chain with the givensegments- Parameters:
builder- thebuildersegments- thesegments
-
-
Method Details
-
extend
- See Also:
extend(int, Builder)
-
extend
- See Also:
extend(Builder)
-
extend
public com.badlogic.gdx.physics.box2d.Body extend()extendsthis Chain using thebuilder- See Also:
extend(Builder)
-
extend
-
shorten
public void shorten()destorysthe last segment -
shorten
public void shorten(int length)destroysthe given amount of segments from the end of the Chain -
createSegment
public com.badlogic.gdx.physics.box2d.Body createSegment(int index)createsa segment for the given index using thebuilder- See Also:
createSegment(int, Builder)
-
createSegment
Creates asegmentusing the givenChain.Builderpassing the correct parameters toChain.Builder.createSegment(int, int, Chain)specified by the givenindex. Does NOT add it to this Chain. -
createConnection
createsa newChain.Connection- See Also:
createConnection(int, int, Builder)
-
createConnection
public Chain.Connection createConnection(int segmentIndex1, int segmentIndex2, Chain.Builder builder)Creates aChain.Connectionusing theChain.Builderpassing 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)addsthe givensegmentto the end of this Chain- Parameters:
segment- thesegmentto add
-
add
public void add(com.badlogic.gdx.physics.box2d.Body... segments)addsthe 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 asegmentinto this Chain- Parameters:
index- theindexat which to insert the givensegmentsegment- thesegmentto 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- thesegmentto insert- Returns:
- the
segmentthat was at the givenindexpreviously
-
remove
public com.badlogic.gdx.physics.box2d.Body remove(com.badlogic.gdx.physics.box2d.Body segment)- Parameters:
segment- TheBodyto remove. Must be asegmentof thisChain.- Returns:
- the given
body - See Also:
remove(int)
-
remove
public com.badlogic.gdx.physics.box2d.Body remove(int index)removes asegmentfrom this Chain- Parameters:
index- the index of thesegmentto 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)removesall 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- thesegmentto destroy- See Also:
destroy(int)
-
destroy
public void destroy(int index)- Parameters:
index- the index of thesegmenttodestroy- See Also:
remove(int)
-
destroy
public void destroy(int beginIndex, int endIndex)destroysall segments from beginIndex to endIndex- Parameters:
beginIndex- the first index to destroyendIndex- the last index to destroy
-
split
- Parameters:
connection- theChain.Connectioninconnectionsto split- Returns:
- the new
Chain - See Also:
split(int)
-
split
splits this Chain at the given index and returns a new Chain consisting of thesegmentsup to the givenindex- Parameters:
connectionIndex- the index of theconnectionto destroy- Returns:
- a Chain consisting of the segments before the given index
-
length
public int length()- Returns:
- the amount of
segmentsin 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
segmentat the given index
-
getConnection
- Parameters:
index- the index of the desiredJoint- Returns:
- the
Jointat 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 toaddits 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 toaddits items to your own collection.- Returns:
- an Array representing the current state of
connections - See Also:
tmpConnections
-
getBuilder
- Returns:
- the
builder
-
setBuilder
- Parameters:
builder- thebuilderto set
-