Package net.dermetfan.gdx.physics.box2d
Class Chain
java.lang.Object
net.dermetfan.gdx.physics.box2d.Chain
Holds
segments and connections to simulate a chain. Also provides modification methods that use a Chain.Builder.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceused by aChainto modify itstatic classholds one or morejointsstatic classstatic classstatic classstatic classaChain.CopyBuilderthat uses aJointDefinChain.JointDefCopyBuilder.createConnection(Body, int, Body, int) -
Constructor Summary
ConstructorsConstructorDescriptionChain(int length, Chain.Builder builder) creates a new Chain andbuildsit to the givenlengthChain(int length, Chain.Builder builder, boolean build) 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 TypeMethodDescriptionvoidadd(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 ChaincreateConnection(int segmentIndex1, int segmentIndex2) createsa newChain.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 thebuilderextend(int length) extend(int length, Chain.Builder builder) com.badlogic.gdx.physics.box2d.Bodyextend(Chain.Builder builder) getConnection(int index) com.badlogic.gdx.utils.Array<Chain.Connection> 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> 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 Chainsplit(int connectionIndex) splits this Chain at the given index and returns a new Chain consisting of thesegmentsup to the givenindexsplit(Chain.Connection connection)
-
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
- 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
- See Also:
-
extend
public com.badlogic.gdx.physics.box2d.Body extend()extendsthis Chain using thebuilder- See Also:
-
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
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.- See Also:
-
createConnection
createsa newChain.Connection- See Also:
-
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.- See Also:
-
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:
-
insert
public com.badlogic.gdx.physics.box2d.Body insert(int index) - See Also:
-
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
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:
-
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:
-
destroy
public void destroy(com.badlogic.gdx.physics.box2d.Body segment) - Parameters:
segment- thesegmentto destroy- See Also:
-
destroy
public void destroy(int index) - Parameters:
index- the index of thesegmenttodestroy- See Also:
-
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
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:
-
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:
-
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:
-
getBuilder
- Returns:
- the
builder
-
setBuilder
- Parameters:
builder- thebuilderto set
-