List of usage examples for com.badlogic.gdx.physics.box2d Shape dispose
public void dispose()
From source file:com.cafeitvn.myballgame.screen.Box2DMapObjectParser.java
License:Apache License
/** * creates a {@link Fixture} from a {@link MapObject} * @param mapObject the {@link MapObject} which to parse * @return the parsed {@link Fixture}/*from w ww. j a va 2 s . c om*/ */ public Fixture createFixture(MapObject mapObject) { MapProperties properties = mapObject.getProperties(); String type = properties.get("type", String.class); Body body = bodies.get( type.equals(aliases.object) ? mapObject.getName() : properties.get(aliases.body, String.class)); if (!type.equals(aliases.fixture) && !type.equals(aliases.object)) throw new IllegalArgumentException("type of " + mapObject + " is \"" + type + "\" instead of \"" + aliases.fixture + "\" or \"" + aliases.object + "\""); FixtureDef fixtureDef = new FixtureDef(); Shape shape = null; if (mapObject instanceof RectangleMapObject) { shape = new PolygonShape(); Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle(); rectangle.x *= unitScale; rectangle.y *= unitScale; rectangle.width *= unitScale; rectangle.height *= unitScale; ((PolygonShape) shape).setAsBox(rectangle.width / 2, rectangle.height / 2, new Vector2(rectangle.x - body.getPosition().x + rectangle.width / 2, rectangle.y - body.getPosition().y + rectangle.height / 2), body.getAngle()); } else if (mapObject instanceof PolygonMapObject) { shape = new PolygonShape(); Polygon polygon = ((PolygonMapObject) mapObject).getPolygon(); polygon.setPosition(polygon.getX() * unitScale - body.getPosition().x, polygon.getY() * unitScale - body.getPosition().y); polygon.setScale(unitScale, unitScale); ((PolygonShape) shape).set(polygon.getTransformedVertices()); } else if (mapObject instanceof PolylineMapObject) { shape = new ChainShape(); Polyline polyline = ((PolylineMapObject) mapObject).getPolyline(); polyline.setPosition(polyline.getX() * unitScale - body.getPosition().x, polyline.getY() * unitScale - body.getPosition().y); polyline.setScale(unitScale, unitScale); ((ChainShape) shape).createChain(polyline.getTransformedVertices()); } else if (mapObject instanceof CircleMapObject) { shape = new CircleShape(); Circle circle = ((CircleMapObject) mapObject).getCircle(); circle.setPosition(circle.x * unitScale - body.getPosition().x, circle.y * unitScale - body.getPosition().y); circle.radius *= unitScale; ((CircleShape) shape).setPosition(new Vector2(circle.x, circle.y)); ((CircleShape) shape).setRadius(circle.radius); } else if (mapObject instanceof EllipseMapObject) { Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse(); if (ellipse.width == ellipse.height) { CircleMapObject circleMapObject = new CircleMapObject(ellipse.x, ellipse.y, ellipse.width / 2); circleMapObject.setName(mapObject.getName()); circleMapObject.getProperties().putAll(mapObject.getProperties()); circleMapObject.setColor(mapObject.getColor()); circleMapObject.setVisible(mapObject.isVisible()); circleMapObject.setOpacity(mapObject.getOpacity()); return createFixture(circleMapObject); } IllegalArgumentException exception = new IllegalArgumentException( "Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s that are not circles are not supported"); Gdx.app.error(getClass().getSimpleName(), exception.getMessage(), exception); throw exception; } else if (mapObject instanceof TextureMapObject) { IllegalArgumentException exception = new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s are not supported"); Gdx.app.error(getClass().getSimpleName(), exception.getMessage(), exception); throw exception; } else assert false : mapObject + " is a not known subclass of " + MapObject.class.getName(); fixtureDef.shape = shape; fixtureDef.density = (Float) getProperty(properties, aliases.density, fixtureDef.density, Float.class); fixtureDef.filter.categoryBits = (Short) getProperty(properties, aliases.categoryBits, fixtureDef.filter.categoryBits, Short.class); fixtureDef.filter.groupIndex = (Short) getProperty(properties, aliases.groupIndex, fixtureDef.filter.groupIndex, Short.class); fixtureDef.filter.maskBits = (Short) getProperty(properties, aliases.maskBits, fixtureDef.filter.maskBits, Short.class); fixtureDef.friction = (Float) getProperty(properties, aliases.friciton, fixtureDef.friction, Float.class); fixtureDef.isSensor = (Boolean) getProperty(properties, aliases.isSensor, fixtureDef.isSensor, Boolean.class); fixtureDef.restitution = (Float) getProperty(properties, aliases.restitution, fixtureDef.restitution, Float.class); Fixture fixture = body.createFixture(fixtureDef); shape.dispose(); String name = mapObject.getName(); if (fixtures.containsKey(name)) { int duplicate = 1; while (fixtures.containsKey(name + duplicate)) duplicate++; name += duplicate; } fixtures.put(name, fixture); return fixture; }
From source file:com.hajnar.GravityShip.GameObjects.BlackHole.java
License:Apache License
public BlackHole(World world, float x, float y, int strength) { super(world, BodyType.StaticBody, OBJECT_TYPE_BLACKHOLE, x, y, 0); sprite = new Sprite(Assets.blackHoleRegions[0]); sprite.setPosition(objectBody.getPosition().x * Helper.BOX_TO_WORLD - sprite.getWidth() / 2, objectBody.getPosition().y * Helper.BOX_TO_WORLD - sprite.getHeight() / 2); timeWarp = new Animation(0.05f, Assets.blackHoleRegions); Shape circle = new CircleShape(); circle.setRadius(0.55f);/*from w w w .java 2s.c o m*/ FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = circle; objectBody.createFixture(fixtureDef); circle.dispose(); objectBody.setUserData(this); animTime = 0; this.strength = strength; }
From source file:com.rubentxu.juegos.core.utils.dermetfan.box2d.Box2DMapObjectParser.java
License:Apache License
/** * creates a {@link Fixture} from a {@link MapObject} * * @param mapObject the {@link MapObject} to parse * @return the parsed {@link Fixture}/*from w w w .ja v a2s . c om*/ */ public Fixture createFixture(MapObject mapObject) { MapProperties properties = mapObject.getProperties(); String type = properties.get("type", String.class); Body body = bodies.get( type.equals(aliases.object) ? mapObject.getName() : properties.get(aliases.body, String.class)); if (!type.equals(aliases.fixture) && !type.equals(aliases.object)) throw new IllegalArgumentException("type of " + mapObject + " is \"" + type + "\" instead of \"" + aliases.fixture + "\" or \"" + aliases.object + "\""); FixtureDef fixtureDef = new FixtureDef(); Shape shape = null; if (mapObject instanceof RectangleMapObject) { shape = new PolygonShape(); Rectangle rectangle = new Rectangle(((RectangleMapObject) mapObject).getRectangle()); rectangle.x *= unitScale; rectangle.y *= unitScale; rectangle.width *= unitScale; rectangle.height *= unitScale; ((PolygonShape) shape).setAsBox(rectangle.width / 2, rectangle.height / 2, new Vector2(rectangle.x - body.getPosition().x + rectangle.width / 2, rectangle.y - body.getPosition().y + rectangle.height / 2), body.getAngle()); } else if (mapObject instanceof PolygonMapObject) { shape = new PolygonShape(); Polygon polygon = ((PolygonMapObject) mapObject).getPolygon(); polygon.setPosition(polygon.getX() * unitScale - body.getPosition().x, polygon.getY() * unitScale - body.getPosition().y); polygon.setScale(unitScale, unitScale); ((PolygonShape) shape).set(polygon.getTransformedVertices()); } else if (mapObject instanceof PolylineMapObject) { shape = new ChainShape(); Polyline polyline = ((PolylineMapObject) mapObject).getPolyline(); polyline.setPosition(polyline.getX() * unitScale - body.getPosition().x, polyline.getY() * unitScale - body.getPosition().y); polyline.setScale(unitScale, unitScale); float[] vertices = polyline.getTransformedVertices(); Vector2[] vectores = new Vector2[vertices.length / 2]; for (int i = 0, j = 0; i < vertices.length; i += 2, j++) { vectores[j].x = vertices[i]; vectores[j].y = vertices[i + 1]; } ((ChainShape) shape).createChain(vectores); } else if (mapObject instanceof CircleMapObject) { shape = new CircleShape(); Circle circle = ((CircleMapObject) mapObject).getCircle(); circle.setPosition(circle.x * unitScale - body.getPosition().x, circle.y * unitScale - body.getPosition().y); circle.radius *= unitScale; ((CircleShape) shape).setPosition(new Vector2(circle.x, circle.y)); ((CircleShape) shape).setRadius(circle.radius); } else if (mapObject instanceof EllipseMapObject) { Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse(); /* b2ChainShape* chain = (b2ChainShape*)addr; b2Vec2* verticesOut = new b2Vec2[numVertices]; for( int i = 0; i < numVertices; i++ ) verticesOut[i] = b2Vec2(verts[i<<1], verts[(i<<1)+1]); chain->CreateChain( verticesOut, numVertices ); delete verticesOut; */ if (ellipse.width == ellipse.height) { CircleMapObject circleMapObject = new CircleMapObject(ellipse.x, ellipse.y, ellipse.width / 2); circleMapObject.setName(mapObject.getName()); circleMapObject.getProperties().putAll(mapObject.getProperties()); circleMapObject.setColor(mapObject.getColor()); circleMapObject.setVisible(mapObject.isVisible()); circleMapObject.setOpacity(mapObject.getOpacity()); return createFixture(circleMapObject); } IllegalArgumentException exception = new IllegalArgumentException( "Cannot parse " + mapObject.getName() + " because that are not circles are not supported"); Gdx.app.error(getClass().getName(), exception.getMessage(), exception); throw exception; } else if (mapObject instanceof TextureMapObject) { IllegalArgumentException exception = new IllegalArgumentException( "Cannot parse " + mapObject.getName() + " because s are not supported"); Gdx.app.error(getClass().getName(), exception.getMessage(), exception); throw exception; } else assert false : mapObject + " is a not known subclass of " + MapObject.class.getName(); fixtureDef.shape = shape; fixtureDef.density = getProperty(properties, aliases.density, fixtureDef.density); fixtureDef.filter.categoryBits = getProperty(properties, aliases.categoryBits, GRUPO.STATIC.getCategory()); fixtureDef.filter.groupIndex = getProperty(properties, aliases.groupIndex, fixtureDef.filter.groupIndex); fixtureDef.filter.maskBits = getProperty(properties, aliases.maskBits, Box2DPhysicsObject.MASK_STATIC); fixtureDef.friction = getProperty(properties, aliases.friciton, fixtureDef.friction); fixtureDef.isSensor = getProperty(properties, aliases.isSensor, fixtureDef.isSensor); fixtureDef.restitution = getProperty(properties, aliases.restitution, fixtureDef.restitution); Fixture fixture = body.createFixture(fixtureDef); fixture.setUserData(body.getUserData()); shape.dispose(); String name = mapObject.getName(); if (fixtures.containsKey(name)) { int duplicate = 1; while (fixtures.containsKey(name + duplicate)) duplicate++; name += duplicate; } fixtures.put(name, fixture); return fixture; }
From source file:com.siondream.core.physics.MapBodyManager.java
License:Open Source License
/** * @param map map to be used to create the static bodies. * @param layerName name of the layer that contains the shapes. *//* ww w. j a v a 2s . c o m*/ public void createPhysics(Map map, String layerName) { MapLayer layer = map.getLayers().get(layerName); if (layer == null) { logger.error("layer " + layerName + " does not exist"); return; } MapObjects objects = layer.getObjects(); Iterator<MapObject> objectIt = objects.iterator(); while (objectIt.hasNext()) { MapObject object = objectIt.next(); if (object instanceof TextureMapObject) { continue; } Shape shape; BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.StaticBody; if (object instanceof RectangleMapObject) { RectangleMapObject rectangle = (RectangleMapObject) object; shape = getRectangle(rectangle); } else if (object instanceof PolygonMapObject) { shape = getPolygon((PolygonMapObject) object); } else if (object instanceof PolylineMapObject) { shape = getPolyline((PolylineMapObject) object); } else if (object instanceof CircleMapObject) { shape = getCircle((CircleMapObject) object); } else { logger.error("non suported shape " + object); continue; } MapProperties properties = object.getProperties(); String material = properties.get("material", "default", String.class); FixtureDef fixtureDef = materials.get(material); if (fixtureDef == null) { logger.error("material does not exist " + material + " using default"); fixtureDef = materials.get("default"); } fixtureDef.shape = shape; //fixtureDef.filter.categoryBits = Env.game.getCategoryBitsManager().getCategoryBits("level"); Body body = world.createBody(bodyDef); body.createFixture(fixtureDef); bodies.add(body); fixtureDef.shape = null; shape.dispose(); } }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java
License:Apache License
/** creates a {@link Fixture} from a {@link MapObject} * @param mapObject the {@link MapObject} to parse * @param body the {@link Body} to create the {@link Fixture Fixtures} on * @return the parsed {@link Fixture} */ public Fixture createFixture(MapObject mapObject, Body body) { if ((mapObject = listener.createFixture(mapObject)) == null) return null; String orientation = findProperty(aliases.orientation, aliases.orthogonal, heritage, mapProperties, layerProperties, mapObject.getProperties()); transform(mat4, orientation);/*w w w .j av a 2s. co m*/ Shape shape = null; if (mapObject instanceof RectangleMapObject) { Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle(); vec3.set(rectangle.x, rectangle.y, 0); vec3.mul(mat4); float x = vec3.x, y = vec3.y, width, height; if (!orientation.equals(aliases.staggered)) { vec3.set(rectangle.width, rectangle.height, 0).mul(mat4); width = vec3.x; height = vec3.y; } else { width = rectangle.width * unitScale; height = rectangle.height * unitScale; } ((PolygonShape) (shape = new PolygonShape())).setAsBox(width / 2, height / 2, vec2.set(x - body.getPosition().x + width / 2, y - body.getPosition().y + height / 2), body.getAngle()); } else if (mapObject instanceof PolygonMapObject || mapObject instanceof PolylineMapObject) { FloatArray vertices = Pools.obtain(FloatArray.class); vertices.clear(); vertices.addAll(mapObject instanceof PolygonMapObject ? ((PolygonMapObject) mapObject).getPolygon().getTransformedVertices() : ((PolylineMapObject) mapObject).getPolyline().getTransformedVertices()); for (int ix = 0, iy = 1; iy < vertices.size; ix += 2, iy += 2) { vec3.set(vertices.get(ix), vertices.get(iy), 0); vec3.mul(mat4); vertices.set(ix, vec3.x - body.getPosition().x); vertices.set(iy, vec3.y - body.getPosition().y); } if (mapObject instanceof PolygonMapObject) ((PolygonShape) (shape = new PolygonShape())).set(vertices.items, 0, vertices.size); else if (vertices.size == 4) ((EdgeShape) (shape = new EdgeShape())).set(vertices.get(0), vertices.get(1), vertices.get(2), vertices.get(3)); else { vertices.shrink(); ((ChainShape) (shape = new ChainShape())).createChain(vertices.items); } Pools.free(vertices); } else if (mapObject instanceof CircleMapObject || mapObject instanceof EllipseMapObject) { if (mapObject instanceof CircleMapObject) { Circle circle = ((CircleMapObject) mapObject).getCircle(); vec3.set(circle.x, circle.y, circle.radius); } else { Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse(); if (ellipse.width != ellipse.height) throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because " + ClassReflection.getSimpleName(mapObject.getClass()) + "s that are not circles are not supported"); vec3.set(ellipse.x + ellipse.width / 2, ellipse.y + ellipse.height / 2, ellipse.width / 2); } vec3.mul(mat4); vec3.sub(body.getPosition().x, body.getPosition().y, 0); CircleShape circleShape = (CircleShape) (shape = new CircleShape()); circleShape.setPosition(vec2.set(vec3.x, vec3.y)); circleShape.setRadius(vec3.z); } else if (mapObject instanceof TextureMapObject) throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because " + ClassReflection.getSimpleName(mapObject.getClass()) + "s are not supported"); else assert false : mapObject + " is a not known subclass of " + MapObject.class.getName(); MapProperties properties = mapObject.getProperties(); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; assignProperties(fixtureDef, heritage); assignProperties(fixtureDef, mapProperties); assignProperties(fixtureDef, layerProperties); assignProperties(fixtureDef, properties); Fixture fixture = body.createFixture(fixtureDef); fixture.setUserData(findProperty(aliases.userData, fixture.getUserData(), heritage, mapProperties, layerProperties, properties)); shape.dispose(); fixtures.put(findAvailableName(mapObject.getName(), fixtures), fixture); listener.created(fixture, mapObject); return fixture; }
From source file:de.fhkoeln.game.utils.Box2DMapObjectParser.java
License:Apache License
/** creates a {@link com.badlogic.gdx.physics.box2d.Fixture} from a {@link com.badlogic.gdx.maps.MapObject} * @param mapObject the {@link com.badlogic.gdx.maps.MapObject} to parse * @param body the {@link com.badlogic.gdx.physics.box2d.Body} to create the {@link com.badlogic.gdx.physics.box2d.Fixture Fixtures} on * @return the parsed {@link com.badlogic.gdx.physics.box2d.Fixture} */ public Fixture createFixture(MapObject mapObject, Body body) { if ((mapObject = listener.createFixture(mapObject)) == null) return null; String orientation = findProperty(aliases.orientation, aliases.orthogonal, heritage, mapProperties, layerProperties, mapObject.getProperties()); transform(mat4, orientation);//from w w w .ja v a2s . c o m Shape shape = null; if (mapObject instanceof RectangleMapObject) { Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle(); vec3.set(rectangle.x, rectangle.y, 0); vec3.mul(mat4); float x = vec3.x, y = vec3.y, width, height; if (!orientation.equals(aliases.staggered)) { vec3.set(rectangle.width, rectangle.height, 0).mul(mat4); width = vec3.x; height = vec3.y; } else { width = rectangle.width * unitScale; height = rectangle.height * unitScale; } ((PolygonShape) (shape = new PolygonShape())).setAsBox(width / 2, height / 2, vec2.set(x - body.getPosition().x + width / 2, y - body.getPosition().y + height / 2), body.getAngle()); } else if (mapObject instanceof PolygonMapObject || mapObject instanceof PolylineMapObject) { FloatArray vertices = Pools.obtain(FloatArray.class); vertices.clear(); vertices.addAll(mapObject instanceof PolygonMapObject ? ((PolygonMapObject) mapObject).getPolygon().getTransformedVertices() : ((PolylineMapObject) mapObject).getPolyline().getTransformedVertices()); for (int ix = 0, iy = 1; iy < vertices.size; ix += 2, iy += 2) { vec3.set(vertices.get(ix), vertices.get(iy), 0); vec3.mul(mat4); vertices.set(ix, vec3.x - body.getPosition().x); vertices.set(iy, vec3.y - body.getPosition().y); } if (mapObject instanceof PolygonMapObject) ((PolygonShape) (shape = new PolygonShape())).set(vertices.items, 0, vertices.size); else if (vertices.size == 4) ((EdgeShape) (shape = new EdgeShape())).set(vertices.get(0), vertices.get(1), vertices.get(2), vertices.get(3)); else { vertices.shrink(); ((ChainShape) (shape = new ChainShape())).createChain(vertices.items); } Pools.free(vertices); } else if (mapObject instanceof CircleMapObject || mapObject instanceof EllipseMapObject) { if (mapObject instanceof CircleMapObject) { Circle circle = ((CircleMapObject) mapObject).getCircle(); vec3.set(circle.x, circle.y, circle.radius); } else { Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse(); if (ellipse.width != ellipse.height) throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s that are not circles are not supported"); vec3.set(ellipse.x + ellipse.width / 2, ellipse.y + ellipse.height / 2, ellipse.width / 2); } vec3.mul(mat4); vec3.sub(body.getPosition().x, body.getPosition().y, 0); CircleShape circleShape = (CircleShape) (shape = new CircleShape()); circleShape.setPosition(vec2.set(vec3.x, vec3.y)); circleShape.setRadius(vec3.z); } else if (mapObject instanceof TextureMapObject) throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s are not supported"); else assert false : mapObject + " is a not known subclass of " + MapObject.class.getName(); MapProperties properties = mapObject.getProperties(); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; assignProperties(fixtureDef, heritage); assignProperties(fixtureDef, mapProperties); assignProperties(fixtureDef, layerProperties); assignProperties(fixtureDef, properties); Fixture fixture = body.createFixture(fixtureDef); fixture.setUserData(findProperty(aliases.userData, fixture.getUserData(), heritage, mapProperties, layerProperties, properties)); shape.dispose(); fixtures.put(findAvailableName(mapObject.getName(), fixtures), fixture); listener.created(fixture, mapObject); return fixture; }
From source file:genuini.world.WorldManager.java
private void createObjectsLayer(World world) { MapObjects objects = objectLayer.getObjects(); sprites = new Array<Sprites>(); turrets = new Array<Turret>(); springs = new Array<Spring>(); buttons = new Array<Button>(); questionBoxes = new Array<QuestionBox>(); for (MapObject object : objects) { if (object instanceof TextureMapObject) { continue; }//from w w w . ja v a 2 s.co m Shape shape; if (object instanceof RectangleMapObject) { shape = getRectangle((RectangleMapObject) object); } else if (object instanceof PolygonMapObject) { shape = getPolygon((PolygonMapObject) object); } else if (object instanceof PolylineMapObject) { shape = getPolyline((PolylineMapObject) object); } else if (object instanceof CircleMapObject) { shape = getCircle((CircleMapObject) object); } else { continue; } float x = new Float(object.getProperties().get("x").toString()); float y = new Float(object.getProperties().get("y").toString()); BodyDef bd = new BodyDef(); bd.type = BodyType.StaticBody; bd.position.x = x / PPM; bd.position.y = y / PPM; Body body = world.createBody(bd); body.createFixture(shape, 1); shape.dispose(); createObject(object, body); } }
From source file:genuini.world.WorldManager.java
private void createAccessPoints() { accessPoints = new Array<AccessPoint>(); MapObjects accessPointsObjects = accessPointsLayer.getObjects(); for (MapObject accessPoint : accessPointsObjects) { if (accessPoint instanceof TextureMapObject) { continue; }/*from w w w .j a v a 2s. co m*/ //Vector2 position = new Vector2(new Float(accessPoint.getProperties().get("x").toString())/PPM,new Float(accessPoint.getProperties().get("y").toString())/PPM); Shape shape = getRectangle((RectangleMapObject) accessPoint); float x = new Float(accessPoint.getProperties().get("x").toString()); float y = new Float(accessPoint.getProperties().get("y").toString()); BodyDef bd = new BodyDef(); bd.type = BodyType.StaticBody; bd.position.x = x / PPM; bd.position.y = y / PPM; Body body = screen.getWorld().createBody(bd); body.createFixture(shape, 1); shape.dispose(); String name = accessPoint.getProperties().get("name").toString(); String type = accessPoint.getProperties().get("type").toString(); AccessPoint ac = new AccessPoint(screen, body, Integer.valueOf(accessPoint.getProperties().get("id").toString()), type, name, accessPoint.getProperties().get("linkedMapName").toString(), accessPoint.getProperties().get("linkedAccessPointName").toString()); accessPoints.add(ac); } }
From source file:genuini.world.WorldManager.java
private void createMobSpawnPoints() { mobSpawnPoints = new Array<MobSpawnPoint>(); MapObjects mobSpawnPointsObjects = mobSpawnPointsLayer.getObjects(); for (MapObject mobSpawnPoint : mobSpawnPointsObjects) { if (mobSpawnPoint instanceof TextureMapObject) { continue; }//w ww . ja v a2 s.c om //Vector2 position = new Vector2(new Float(mobSpawnPoint.getProperties().get("x").toString())/PPM,new Float(mobSpawnPoint.getProperties().get("y").toString())/PPM); Shape shape = getRectangle((RectangleMapObject) mobSpawnPoint); float x = new Float(mobSpawnPoint.getProperties().get("x").toString()); float y = new Float(mobSpawnPoint.getProperties().get("y").toString()); BodyDef bd = new BodyDef(); bd.type = BodyType.StaticBody; bd.position.x = x / PPM; bd.position.y = y / PPM; Body body = screen.getWorld().createBody(bd); body.createFixture(shape, 1); shape.dispose(); String mobType = mobSpawnPoint.getProperties().get("mobType").toString(); float area = Float.valueOf(mobSpawnPoint.getProperties().get("area").toString()); int maxMobs = Integer.valueOf(mobSpawnPoint.getProperties().get("maxMobs").toString()); MobSpawnPoint msp = new MobSpawnPoint(screen, body, Integer.valueOf(mobSpawnPoint.getProperties().get("id").toString()), mobType, area, maxMobs); mobSpawnPoints.add(msp); } }
From source file:me.scarlet.undertailor.engine.overworld.Entrypoint.java
License:Open Source License
@Override public boolean claim(WorldRoom parent) { if (this.parent == null) { this.parent = parent; String[] defShape = this.mapEntrypoint.split(":"); this.bodyData = this.parent.getMap().getDefinedShape(defShape[0], defShape[1]); if (this.spawnPoint == null) { String rawPoint = this.parent.getMap().getEntrypointSpawn(this.mapEntrypoint); if (rawPoint != null && !rawPoint.trim().isEmpty()) { String[] defPoint = rawPoint.split(":"); this.spawnPoint = this.parent.getMap().getDefinedPoint(defPoint[0], defPoint[1]); }/* ww w.j a va 2 s .c o m*/ } if (this.bodyData != null) { float ptm = OverworldController.PIXELS_TO_METERS; BodyDef def = new BodyDef(); def.type = BodyType.StaticBody; def.position.set(bodyData.getPosition()); def.position.x = def.position.x * ptm; def.position.y = def.position.y * ptm; Shape shape = bodyData.generateShape(); this.body = parent.getOverworld().getCollisionHandler().getWorld().createBody(def); this.body.createFixture(shape, 0F); this.body.setUserData(this); shape.dispose(); } return true; } return false; }