public class Box2DMapObjectParser
extends java.lang.Object
MapObjects from a Map and generates Box2D Bodies, Fixtures and Joints from them.Box2DMapObjectParser and call load(World, MapLayer) to load all compatible objects (defined by the the aliases) into your World.createBody(World, MapObject) and createFixture(MapObject) methods.object) you'd like, as defined in the used Box2DMapObjectParser.Aliases object.Box2DMapObjectParser.Aliases.body, Box2DMapObjectParser.Aliases.fixture or Box2DMapObjectParser.Aliases.object.Box2DMapObjectParser.Aliases.body property with the same value to each Fixture of a Body.Joints, add any object to the layer and just put everything needed in its properties. Note that you use the editors unit here which will be converted to Box2D meters automatically using Box2DMapObjectParser.Aliases.unitScale.
| Modifier and Type | Class and Description |
|---|---|
static class |
Box2DMapObjectParser.Aliases
defines the
aliases to use when parsing |
static interface |
Box2DMapObjectParser.Listener
Allows modification of
MapObjects before they are used to create Box2D objects. |
| Modifier and Type | Field and Description |
|---|---|
private Box2DMapObjectParser.Aliases |
aliases |
private com.badlogic.gdx.utils.ObjectMap<java.lang.String,com.badlogic.gdx.physics.box2d.Body> |
bodies
the parsed
Bodies |
static Box2DMapObjectParser.Listener.Adapter |
defaultListener
the
Box2DMapObjectParser.Listener used by default (an Box2DMapObjectParser.Listener.Adapter instance) |
private com.badlogic.gdx.utils.ObjectMap<java.lang.String,com.badlogic.gdx.physics.box2d.Fixture> |
fixtures
the parsed
Fixtures |
private com.badlogic.gdx.maps.MapProperties |
heritage
the properties
MapObjects will inherit in createBody(World, MapObject), createFixture(MapObject) and createJoint(MapObject) |
private boolean |
ignoreLayerUnitScale
if the
unit scale found in the layers should be ignored |
private boolean |
ignoreMapUnitScale
if the
unit scale found in the map should be ignored |
private com.badlogic.gdx.utils.ObjectMap<java.lang.String,com.badlogic.gdx.physics.box2d.Joint> |
joints
the parsed
Joints |
private com.badlogic.gdx.maps.MapProperties |
layerProperties
the
MapProperties of the currently loading layer |
private Box2DMapObjectParser.Listener |
listener
the
Box2DMapObjectParser.Listener to use (defaultListener by default) |
private com.badlogic.gdx.maps.MapProperties |
mapProperties
the
MapProperties of the currently loading map |
private com.badlogic.gdx.math.Matrix4 |
mat4
for internal, temporary usage
|
private float |
tileHeight
the dimensions of a tile, used to transform positions (ignore/set to 1 if the map is not a tile map)
|
private float |
tileWidth
the dimensions of a tile, used to transform positions (ignore/set to 1 if the map is not a tile map)
|
private boolean |
triangulate
if concave polygons should be triangulated instead of being decomposed into convex polygons
|
private float |
unitScale
the unit scale to convert from editor units to Box2D meters
|
private com.badlogic.gdx.math.Vector2 |
vec2
for internal, temporary usage
|
private com.badlogic.gdx.math.Vector3 |
vec3
for internal, temporary usage
|
| Modifier and Type | Method and Description |
|---|---|
void |
assignProperties(com.badlogic.gdx.physics.box2d.BodyDef bodyDef,
com.badlogic.gdx.maps.MapProperties properties)
assigns the given
properties to the values of the given BodyDef |
void |
assignProperties(com.badlogic.gdx.physics.box2d.joints.DistanceJointDef distanceJointDef,
com.badlogic.gdx.maps.MapProperties properties)
assigns all properties unique to the given joint definition
|
void |
assignProperties(com.badlogic.gdx.physics.box2d.FixtureDef fixtureDef,
com.badlogic.gdx.maps.MapProperties properties) |
void |
assignProperties(com.badlogic.gdx.physics.box2d.joints.FrictionJointDef frictionJointDef,
com.badlogic.gdx.maps.MapProperties properties)
assigns all properties unique to the given joint definition
|
void |
assignProperties(com.badlogic.gdx.physics.box2d.joints.GearJointDef gearJointDef,
com.badlogic.gdx.maps.MapProperties properties)
assigns all properties unique to the given joint definition
|
void |
assignProperties(com.badlogic.gdx.physics.box2d.JointDef jointDef,
com.badlogic.gdx.maps.MapProperties properties)
assigns the common properties of all JointDefs
|
void |
assignProperties(com.badlogic.gdx.physics.box2d.joints.MouseJointDef mouseJointDef,
com.badlogic.gdx.maps.MapProperties properties)
assigns all properties unique to the given joint definition
|
void |
assignProperties(com.badlogic.gdx.physics.box2d.joints.PrismaticJointDef prismaticJointDef,
com.badlogic.gdx.maps.MapProperties properties)
assigns all properties unique to the given joint definition
|
void |
assignProperties(com.badlogic.gdx.physics.box2d.joints.PulleyJointDef pulleyJointDef,
com.badlogic.gdx.maps.MapProperties properties)
assigns all properties unique to the given joint definition
|
void |
assignProperties(com.badlogic.gdx.physics.box2d.joints.RevoluteJointDef revoluteJointDef,
com.badlogic.gdx.maps.MapProperties properties)
assigns all properties unique to the given joint definition
|
void |
assignProperties(com.badlogic.gdx.physics.box2d.joints.RopeJointDef ropeJointDef,
com.badlogic.gdx.maps.MapProperties properties)
assigns all properties unique to the given joint definition
|
void |
assignProperties(com.badlogic.gdx.physics.box2d.joints.WeldJointDef weldJointDef,
com.badlogic.gdx.maps.MapProperties properties)
assigns all properties unique to the given joint definition
|
void |
assignProperties(com.badlogic.gdx.physics.box2d.joints.WheelJointDef wheelJointDef,
com.badlogic.gdx.maps.MapProperties properties)
assigns all properties unique to the given joint definition
|
com.badlogic.gdx.physics.box2d.Body |
createBody(com.badlogic.gdx.physics.box2d.World world,
com.badlogic.gdx.maps.MapObject mapObject)
creates a
Body in the given World from the given MapObject |
com.badlogic.gdx.physics.box2d.Fixture |
createFixture(com.badlogic.gdx.maps.MapObject mapObject)
|
com.badlogic.gdx.physics.box2d.Fixture |
createFixture(com.badlogic.gdx.maps.MapObject mapObject,
com.badlogic.gdx.physics.box2d.Body body)
creates a
Fixture from a MapObject |
com.badlogic.gdx.physics.box2d.Fixture[] |
createFixtures(com.badlogic.gdx.maps.MapObject mapObject)
|
com.badlogic.gdx.physics.box2d.Fixture[] |
createFixtures(com.badlogic.gdx.maps.MapObject mapObject,
com.badlogic.gdx.physics.box2d.Body body)
creates
Fixtures from a MapObject |
com.badlogic.gdx.physics.box2d.Joint |
createJoint(com.badlogic.gdx.maps.MapObject mapObject)
creates a
Joint from a MapObject |
com.badlogic.gdx.physics.box2d.Body |
createObject(com.badlogic.gdx.physics.box2d.World world,
com.badlogic.gdx.maps.MapObject object) |
static java.lang.String |
findAvailableName(java.lang.String desiredName,
com.badlogic.gdx.utils.ObjectMap<java.lang.String,?> map) |
private com.badlogic.gdx.physics.box2d.Body |
findBody(com.badlogic.gdx.maps.MapObject mapObject,
com.badlogic.gdx.maps.MapProperties... heritage) |
Box2DMapObjectParser.Aliases |
getAliases() |
com.badlogic.gdx.utils.ObjectMap<java.lang.String,com.badlogic.gdx.physics.box2d.Body> |
getBodies() |
com.badlogic.gdx.utils.ObjectMap<java.lang.String,com.badlogic.gdx.physics.box2d.Fixture> |
getFixtures() |
com.badlogic.gdx.maps.MapProperties |
getHeritage() |
com.badlogic.gdx.utils.ObjectMap<java.lang.String,com.badlogic.gdx.physics.box2d.Joint> |
getJoints() |
Box2DMapObjectParser.Listener |
getListener() |
float |
getTileHeight() |
float |
getTileWidth() |
float |
getUnitScale() |
boolean |
isIgnoreLayerUnitScale() |
boolean |
isIgnoreMapUnitScale() |
boolean |
isTriangulate() |
com.badlogic.gdx.physics.box2d.World |
load(com.badlogic.gdx.physics.box2d.World world,
com.badlogic.gdx.maps.Map map)
creates the given
Map's MapObjects in the given World |
com.badlogic.gdx.physics.box2d.World |
load(com.badlogic.gdx.physics.box2d.World world,
com.badlogic.gdx.maps.MapLayer layer)
creates the given
MapLayer's MapObjects in the given World |
void |
reset()
resets all fields to their default values
|
void |
setAliases(Box2DMapObjectParser.Aliases aliases) |
void |
setHeritage(com.badlogic.gdx.maps.MapProperties heritage) |
void |
setIgnoreLayerUnitScale(boolean ignoreLayerUnitScale) |
void |
setIgnoreMapUnitScale(boolean ignoreMapUnitScale) |
void |
setListener(Box2DMapObjectParser.Listener listener) |
void |
setTileHeight(float tileHeight) |
void |
setTileWidth(float tileWidth) |
void |
setTriangulate(boolean triangulate) |
void |
setUnitScale(float unitScale) |
void |
transform(com.badlogic.gdx.math.Matrix4 mat,
java.lang.String orientation)
transforms the given matrix according to the given orientation
|
private Box2DMapObjectParser.Aliases aliases
Box2DMapObjectParser.Aliasespublic static final Box2DMapObjectParser.Listener.Adapter defaultListener
Box2DMapObjectParser.Listener used by default (an Box2DMapObjectParser.Listener.Adapter instance)private Box2DMapObjectParser.Listener listener
Box2DMapObjectParser.Listener to use (defaultListener by default)private float unitScale
private boolean ignoreMapUnitScale
unit scale found in the map should be ignoredprivate boolean ignoreLayerUnitScale
unit scale found in the layers should be ignoredprivate float tileWidth
private float tileHeight
private boolean triangulate
private com.badlogic.gdx.maps.MapProperties heritage
MapObjects will inherit in createBody(World, MapObject), createFixture(MapObject) and createJoint(MapObject)private com.badlogic.gdx.utils.ObjectMap<java.lang.String,com.badlogic.gdx.physics.box2d.Body> bodies
Bodiesprivate com.badlogic.gdx.utils.ObjectMap<java.lang.String,com.badlogic.gdx.physics.box2d.Fixture> fixtures
Fixturesprivate com.badlogic.gdx.utils.ObjectMap<java.lang.String,com.badlogic.gdx.physics.box2d.Joint> joints
Jointsprivate com.badlogic.gdx.maps.MapProperties mapProperties
MapProperties of the currently loading mapprivate com.badlogic.gdx.maps.MapProperties layerProperties
MapProperties of the currently loading layerprivate final com.badlogic.gdx.math.Vector2 vec2
private final com.badlogic.gdx.math.Vector3 vec3
private final com.badlogic.gdx.math.Matrix4 mat4
public Box2DMapObjectParser()
Box2DMapObjectParser with the default Box2DMapObjectParser.Aliasespublic Box2DMapObjectParser(Box2DMapObjectParser.Aliases aliases)
Box2DMapObjectParser using the given Box2DMapObjectParser.Aliasesaliases - the aliases to usepublic Box2DMapObjectParser(Box2DMapObjectParser.Listener listener)
Box2DMapObjectParser using the given Box2DMapObjectParser.Listenerlistener - the listener to usepublic Box2DMapObjectParser(Box2DMapObjectParser.Aliases aliases, Box2DMapObjectParser.Listener listener)
Box2DMapObjectParser using the given Box2DMapObjectParser.Aliases and Box2DMapObjectParser.Listenerpublic Box2DMapObjectParser(Box2DMapObjectParser.Aliases aliases, float tileWidth, float tileHeight)
Box2DMapObjectParser using the given Box2DMapObjectParser.Aliases, tileWidth and tileHeightaliases - the aliasestileWidth - the tileWidthtileHeight - the tileHeightpublic Box2DMapObjectParser(Box2DMapObjectParser.Listener listener, float tileWidth, float tileHeight)
Box2DMapObjectParser using the given Box2DMapObjectParser.Listener, tileWidth and tileHeightlistener - the listenertileWidth - the tileWidthtileHeight - the tileHeightpublic Box2DMapObjectParser(Box2DMapObjectParser.Aliases aliases, Box2DMapObjectParser.Listener listener, float tileWidth, float tileHeight)
Box2DMapObjectParser using the given Box2DMapObjectParser.Listener, Box2DMapObjectParser.Aliases, tileWidth and tileHeightaliases - the aliaseslistener - the listenertileWidth - the tileWidthtileHeight - the tileHeightpublic Box2DMapObjectParser(float unitScale)
unitScale - the unitScale to usepublic Box2DMapObjectParser(float unitScale,
float tileWidth,
float tileHeight)
Box2DMapObjectParser using the given unitScale, tileWidth, tileHeight and sets ignoreMapUnitScale to trueunitScale - the unitScale to usetileWidth - the tileWidth to usetileHeight - the tileHeight to usepublic Box2DMapObjectParser(Box2DMapObjectParser.Aliases aliases, float unitScale)
Box2DMapObjectParser using the given Box2DMapObjectParser.Aliases and unitScale and sets ignoreMapUnitScale to truepublic Box2DMapObjectParser(Box2DMapObjectParser.Listener listener, float unitScale)
Box2DMapObjectParser using the given Box2DMapObjectParser.Listener and unitScale and sets ignoreMapUnitScale to truepublic Box2DMapObjectParser(Box2DMapObjectParser.Aliases aliases, Box2DMapObjectParser.Listener listener, float unitScale)
Box2DMapObjectParser using the given Box2DMapObjectParser.Aliases, Box2DMapObjectParser.Listener and unitScale and sets ignoreMapUnitScale to truepublic Box2DMapObjectParser(Box2DMapObjectParser.Aliases aliases, float unitScale, float tileWidth, float tileHeight)
Box2DMapObjectParser with the given parameters and sets ignoreMapUnitScale to truealiases - the aliases to useunitScale - the unitScale to usetileWidth - the tileWidth to usetileHeight - the tileHeight to usepublic Box2DMapObjectParser(Box2DMapObjectParser.Listener listener, float unitScale, float tileWidth, float tileHeight)
Box2DMapObjectParser with the given parameters and sets ignoreMapUnitScale to truelistener - the listener to useunitScale - the unitScale to usetileWidth - the tileWidth to usetileHeight - the tileHeight to usepublic Box2DMapObjectParser(Box2DMapObjectParser.Listener listener, Box2DMapObjectParser.Aliases aliases, float unitScale, float tileWidth, float tileHeight)
Box2DMapObjectParser with the given parameters and sets ignoreMapUnitScale to truealiases - the aliases to uselistener - the listener to useunitScale - the unitScale to usetileWidth - the tileWidth to usetileHeight - the tileHeight to usepublic com.badlogic.gdx.physics.box2d.World load(com.badlogic.gdx.physics.box2d.World world,
com.badlogic.gdx.maps.Map map)
Map's MapObjects in the given Worldworld - the World to create the MapObjects of the given Map inmap - the Map which MapObjects to create in the given WorldWorld with the parsed MapObjects of the given Map created in itpublic com.badlogic.gdx.physics.box2d.World load(com.badlogic.gdx.physics.box2d.World world,
com.badlogic.gdx.maps.MapLayer layer)
MapLayer's MapObjects in the given Worldworld - the World to create the MapObjects of the given MapLayer inlayer - the MapLayer which MapObjects to create in the given WorldWorld with the parsed MapObjects of the given MapLayer created in itpublic com.badlogic.gdx.physics.box2d.Body createObject(com.badlogic.gdx.physics.box2d.World world,
com.badlogic.gdx.maps.MapObject object)
world - the World in which to create the Body and Fixturesobject - the MapObject to parsecreateBody(World, MapObject),
createFixtures(MapObject)public com.badlogic.gdx.physics.box2d.Body createBody(com.badlogic.gdx.physics.box2d.World world,
com.badlogic.gdx.maps.MapObject mapObject)
Body in the given World from the given MapObjectworld - the World to create the Body inmapObject - the MapObject to parse the Body fromBody created in the given World from the given MapObjectpublic com.badlogic.gdx.physics.box2d.Fixture createFixture(com.badlogic.gdx.maps.MapObject mapObject,
com.badlogic.gdx.physics.box2d.Body body)
Fixture from a MapObjectmapObject - the MapObject to parsebody - the Body to create the Fixtures onFixturepublic com.badlogic.gdx.physics.box2d.Fixture[] createFixtures(com.badlogic.gdx.maps.MapObject mapObject,
com.badlogic.gdx.physics.box2d.Body body)
Fixtures from a MapObjectmapObject - the MapObject to parsebody - the Body to create the Fixtures onFixturespublic com.badlogic.gdx.physics.box2d.Fixture createFixture(com.badlogic.gdx.maps.MapObject mapObject)
createFixture(MapObject, Body)public com.badlogic.gdx.physics.box2d.Fixture[] createFixtures(com.badlogic.gdx.maps.MapObject mapObject)
createFixtures(MapObject, Body)public void transform(com.badlogic.gdx.math.Matrix4 mat,
java.lang.String orientation)
mat - the matrix to transformorientation - the orientationprivate com.badlogic.gdx.physics.box2d.Body findBody(com.badlogic.gdx.maps.MapObject mapObject,
com.badlogic.gdx.maps.MapProperties... heritage)
heritage - the MapProperties in which to search for an Box2DMapObjectParser.Aliases.body propertyMapObjectpublic com.badlogic.gdx.physics.box2d.Joint createJoint(com.badlogic.gdx.maps.MapObject mapObject)
Joint from a MapObjectmapObject - the Joint to parseJointpublic void assignProperties(com.badlogic.gdx.physics.box2d.BodyDef bodyDef,
com.badlogic.gdx.maps.MapProperties properties)
properties to the values of the given BodyDefbodyDef - the BodyDef which values to set according to the given MapPropertiesproperties - the MapProperties to assign to the given BodyDefpublic void assignProperties(com.badlogic.gdx.physics.box2d.FixtureDef fixtureDef,
com.badlogic.gdx.maps.MapProperties properties)
assignProperties(BodyDef, MapProperties)public void assignProperties(com.badlogic.gdx.physics.box2d.JointDef jointDef,
com.badlogic.gdx.maps.MapProperties properties)
public void assignProperties(com.badlogic.gdx.physics.box2d.joints.DistanceJointDef distanceJointDef,
com.badlogic.gdx.maps.MapProperties properties)
public void assignProperties(com.badlogic.gdx.physics.box2d.joints.FrictionJointDef frictionJointDef,
com.badlogic.gdx.maps.MapProperties properties)
public void assignProperties(com.badlogic.gdx.physics.box2d.joints.GearJointDef gearJointDef,
com.badlogic.gdx.maps.MapProperties properties)
public void assignProperties(com.badlogic.gdx.physics.box2d.joints.MouseJointDef mouseJointDef,
com.badlogic.gdx.maps.MapProperties properties)
public void assignProperties(com.badlogic.gdx.physics.box2d.joints.PrismaticJointDef prismaticJointDef,
com.badlogic.gdx.maps.MapProperties properties)
public void assignProperties(com.badlogic.gdx.physics.box2d.joints.PulleyJointDef pulleyJointDef,
com.badlogic.gdx.maps.MapProperties properties)
public void assignProperties(com.badlogic.gdx.physics.box2d.joints.RevoluteJointDef revoluteJointDef,
com.badlogic.gdx.maps.MapProperties properties)
public void assignProperties(com.badlogic.gdx.physics.box2d.joints.RopeJointDef ropeJointDef,
com.badlogic.gdx.maps.MapProperties properties)
public void assignProperties(com.badlogic.gdx.physics.box2d.joints.WeldJointDef weldJointDef,
com.badlogic.gdx.maps.MapProperties properties)
public void assignProperties(com.badlogic.gdx.physics.box2d.joints.WheelJointDef wheelJointDef,
com.badlogic.gdx.maps.MapProperties properties)
public static java.lang.String findAvailableName(java.lang.String desiredName,
com.badlogic.gdx.utils.ObjectMap<java.lang.String,?> map)
public void reset()
public float getUnitScale()
unitScalepublic void setUnitScale(float unitScale)
unitScale - the unitScale to setpublic boolean isIgnoreMapUnitScale()
ignoreMapUnitScalepublic void setIgnoreMapUnitScale(boolean ignoreMapUnitScale)
ignoreMapUnitScale - the ignoreMapUnitScale to setpublic boolean isIgnoreLayerUnitScale()
ignoreLayerUnitScalepublic void setIgnoreLayerUnitScale(boolean ignoreLayerUnitScale)
ignoreLayerUnitScale - the ignoreLayerUnitScale to setpublic float getTileWidth()
tileWidthpublic void setTileWidth(float tileWidth)
tileWidth - the tileWidth to setpublic float getTileHeight()
tileHeightpublic void setTileHeight(float tileHeight)
tileHeight - the tileHeight to setpublic boolean isTriangulate()
triangulatepublic void setTriangulate(boolean triangulate)
triangulate - the triangulate to setpublic Box2DMapObjectParser.Aliases getAliases()
Box2DMapObjectParser.Aliasespublic void setAliases(Box2DMapObjectParser.Aliases aliases)
aliases - the Box2DMapObjectParser.Aliases to setpublic Box2DMapObjectParser.Listener getListener()
listenerpublic void setListener(Box2DMapObjectParser.Listener listener)
listener - the listener to setpublic com.badlogic.gdx.utils.ObjectMap<java.lang.String,com.badlogic.gdx.physics.box2d.Body> getBodies()
bodiespublic com.badlogic.gdx.utils.ObjectMap<java.lang.String,com.badlogic.gdx.physics.box2d.Fixture> getFixtures()
fixturespublic com.badlogic.gdx.utils.ObjectMap<java.lang.String,com.badlogic.gdx.physics.box2d.Joint> getJoints()
jointspublic com.badlogic.gdx.maps.MapProperties getHeritage()
heritagepublic void setHeritage(com.badlogic.gdx.maps.MapProperties heritage)
heritage - the heritage to set