public static FixtureDef getFixtureDefFromBodySkeleton(MapObject object) { FixtureDef fixtureDef = new FixtureDef(); fixtureDef.density = 1; fixtureDef.friction = 0; fixtureDef.restitution = 0; Shape shape = null; if (object instanceof TextureMapObject) { shape = getTextureMapShape(object); } else if (object instanceof RectangleMapObject) { shape = getRectangleShape(object); } else if (object instanceof CircleMapObject) { shape = getCircleShape(object); } else if (object instanceof EllipseMapObject) { shape = getEllipseShape(object); } else if (object instanceof PolygonMapObject) { shape = getPolygonShape(object); } else if (object instanceof PolylineMapObject) { shape = getPolylineShape(object); } fixtureDef.shape = shape; return fixtureDef; }
private void processLayer(MapLayerWrapper layer) { Array<MapObject> freeBodies = new Array<MapObject>(); Array<TextureMapObject> entities = new Array<TextureMapObject>(); Array<TextureMapObject> scripts = new Array<TextureMapObject>(); for (MapObject object : layer.getObjects()) { if (object instanceof TextureMapObject) { if (layer.getName().equals("bodies")) { entities.add((TextureMapObject)object); } else if (layer.getName().equals("scripts")) { scripts.add((TextureMapObject)object); } } else { if (!TiledUtils.propertyExists(object, "type")) { freeBodies.add(object); } else { String type = TiledUtils.getStringProperty(object, "type"); if (isBodySkeleton(type)) { bodySkeletonMap.put(object.getName(), object); } else { throw new InvalidConfigException(filename, "type", type); } } } } if (layer.getName().equals("scripts")) { processScripts(scripts); } else { processFreeBodies(freeBodies); processEntities(layer, entities); } }
private void processScripts(Array<TextureMapObject> scripts) { for (TextureMapObject object : scripts) { if (!TiledUtils.propertyExists(object, "type")) { throw new InvalidConfigException(filename, "type", "null"); } String type = TiledUtils.getStringProperty(object, "type"); PropertyValidator.validateAndProcess(ScriptPropertyConfiguration.getInstance(), type, object.getProperties()); ScriptDefinition scriptDefinition = new TiledScriptDefinition(object.getName(), type, object.getProperties()); scriptDefinitions.add(scriptDefinition); } }
private int getLayerPosition(MapLayerWrapper layer, TextureMapObject object) { if (TiledUtils.propertyExists(object, "layer")) { return TiledUtils.getIntProperty(object, "layer"); } else if (TiledUtils.propertyExists(layer, "layer")) { return TiledUtils.getIntProperty(layer, "layer"); } else { throw new InvalidConfigException(filename, "layer", "null"); } }
private static Shape getTextureMapShape(MapObject object) { TextureMapObject textureMapObject = (TextureMapObject)object; float width = (Float)textureMapObject.getProperties().get("width"); float height = (Float)textureMapObject.getProperties().get("height"); PolygonShape shape = new PolygonShape(); float scale = MainCamera.getInstance().getTileMapScale(); shape.setAsBox((width / 2) * scale, (height / 2) * scale); return shape; }
@Test public void testBuildEntity () { TiledMap map = mapRegistry.getRegisteredMaps().get("testMap"); Assert.assertNotNull (map); mapObjectManager.setMapInfo(new TiledMapInfo (map)); MapLayer objectLayer = map.getLayers().get(MapObjectManager.OBJECT_LAYER_NAME); assertEquals (1, objectLayer.getObjects().getCount()); TextureMapObjectSpawnParams params = new TextureMapObjectSpawnParams(); params.setId(UiManager.BLANK_IMAGE); eventPublisher.publishEvent(new SpawnEntityEvent(this, TextureMapObject.class, params)); assertEquals (2, objectLayer.getObjects().getCount()); }
/** * * @param entityModel * @param position Model position * @param image */ public TextureMapObject addMapObject(MetadataHolderBlock entityModel, Position position, TextureRegion image) { MapLayer objectLayer = getMap().getLayers().get(OBJECT_LAYER_NAME); TextureMapObject tmo = new TextureMapObject(image); Position screenPosition = getPositionForModelEntity (entityModel, position); tmo.setX(screenPosition.getX()); tmo.setY(screenPosition.getY()); objectLayer.getObjects().add(tmo); textureMapObjectsMap.put(entityModel, tmo); return tmo; }
public void updateTextureMapObjectPosition(MetadataHolderBlock entityModel, Position position) { TextureMapObject tmo = this.textureMapObjectsMap.get(entityModel); Position screenPosition = getPositionForModelEntity (entityModel, position); tmo.setX(screenPosition.getX()); tmo.setY(screenPosition.getY()); log.debug("New model position: "+position); log.debug(String.format("New image position: %.2f/%.2f", tmo.getX(), tmo.getY())); //log.debug(String.format("Camera position: %.2f/%.2f", getCamera().getOrthoCam().position.x, getCamera().getOrthoCam().position.y)); }
@Override public void renderObject(MapObject object) { if(object instanceof TextureMapObject) { TextureMapObject textureObj = (TextureMapObject) object; batch.draw(textureObj.getTextureRegion(), textureObj.getX(), textureObj.getY()); } }
@Override public void renderObject(MapObject object) { if(object instanceof TextureMapObject) { TextureMapObject textureObj = (TextureMapObject) object; batch.draw(textureObj.getTextureRegion(), textureObj.getX(), textureObj.getY()); //log.info("TextureMapObject coords: "+ textureObj.getX()+"/"+ textureObj.getY()); } }
public void placeCreatures() { for (MetadataHolderBlock entity : this.getModel().getCreatures()) { TextureRegion image = guiManager.getImageForEntity(entity.getMetadata().getId()); TextureMapObject tmo = this.addMapObject( entity, ((PositionHolderBlock) entity).getPositionAspect(), image); } }
public TextureMapObject addMapObject(MetadataHolderBlock entityModel, Position position, String imageCode) { return addMapObject(entityModel, position, UiManager.instance().getImage(imageCode)); }
public void removeMapObject (MetadataHolderBlock entityModel) { MapLayer objectLayer = getMap().getLayers().get(OBJECT_LAYER_NAME); TextureMapObject tmo = textureMapObjectsMap.get(entityModel); objectLayer.getObjects().remove(tmo); textureMapObjectsMap.remove(entityModel); }
@Override public List<Class<?>> getSupportedClasses() { return new InlineGList<>(TextureMapObject.class); }
@Override public TextureMapObject spawnEntity(TextureMapObjectSpawnParams params) { return mapObjectManager.addMapObject(params.getModelEntity(), params.getPosition(), params.getId()); }
private void crearColisiones() { Array<Body> slopes = new Array<Body>(); FixtureDef fixDef = new FixtureDef(); MapObjects objects = cls.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 EllipseMapObject) { shape = getEllipse((EllipseMapObject)object); } else if (object instanceof CircleMapObject) { shape = getCircle((CircleMapObject)object); } else { continue; } fixDef.shape = shape; fixDef.filter.categoryBits = GameWorld.BIT_PARED; fixDef.filter.maskBits = GameWorld.BIT_JUGADOR | GameWorld.BIT_ENEMIGOS | GameWorld.BIT_SENSOR; Body suelo = GameWorld.mundo.createBody(bodyDef); suelo.createFixture(fixDef).setUserData("cls"); slopes.add(suelo); shape.dispose(); } }
/** * @param map map to be used to create the static bodies. * @param layerName name of the layer that contains the shapes. */ 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(); } }
/** * * @param entityModel * @param position Model position * @param image */ public TextureMapObject addMapObject(MetadataHolderBlock entityModel, Position position, TextureRegion image) { Validate.notNull(image); return mapObjectManager.addMapObject(entityModel, position, image); }