Java 类com.badlogic.gdx.maps.objects.TextureMapObject 实例源码

项目:joe    文件:TiledUtils.java   
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;
}
项目:joe    文件:TiledMapLevelLoadable.java   
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);
    }
}
项目:joe    文件:TiledMapLevelLoadable.java   
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);
    }
}
项目:joe    文件:TiledMapLevelLoadable.java   
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");
    }
}
项目:joe    文件:TiledUtils.java   
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;
}
项目:swampmachine    文件:TextureMapObjectFactoryTest.java   
@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());
}
项目:swampmachine    文件:MapObjectManager.java   
/**
 * 
 * @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;
}
项目:swampmachine    文件:MapObjectManager.java   
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));
}
项目:swampmachine    文件:IsometricTiledMapRendererWithObjects.java   
@Override
public void renderObject(MapObject object) {
    if(object instanceof TextureMapObject) {
        TextureMapObject textureObj = (TextureMapObject) object;
            batch.draw(textureObj.getTextureRegion(), textureObj.getX(), textureObj.getY());
    }
}
项目:swampmachine    文件:OrthogonalTiledMapRendererWithObjects.java   
@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());
    }
}
项目:swampmachine    文件:AbstractTiledMapView.java   
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);
    }
}
项目:swampmachine    文件:MapObjectManager.java   
public TextureMapObject addMapObject(MetadataHolderBlock entityModel, Position position, String imageCode) {
    return addMapObject(entityModel, position, UiManager.instance().getImage(imageCode));
}
项目:swampmachine    文件:MapObjectManager.java   
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);
}
项目:swampmachine    文件:TextureMapObjectFactory.java   
@Override
public List<Class<?>> getSupportedClasses() {
    return new InlineGList<>(TextureMapObject.class);
}
项目:swampmachine    文件:TextureMapObjectFactory.java   
@Override
public TextureMapObject spawnEntity(TextureMapObjectSpawnParams params) {
    return mapObjectManager.addMapObject(params.getModelEntity(), params.getPosition(), params.getId());
}
项目:practicos    文件:GeneradorNivel.java   
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();
  }
}
项目:sioncore    文件:MapBodyManager.java   
/**
 * @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();
    }
}
项目:swampmachine    文件:AbstractTiledMapView.java   
/**
 * 
 * @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);
}