Example usage for com.badlogic.gdx.maps.objects TextureMapObject getX

List of usage examples for com.badlogic.gdx.maps.objects TextureMapObject getX

Introduction

In this page you can find the example usage for com.badlogic.gdx.maps.objects TextureMapObject getX.

Prototype

public float getX() 

Source Link

Usage

From source file:releasethekraken.entity.Entity.java

/**
 * Constructs an Entity from a TextureMapObject that represents it in a
 * level file.  /*from   w  ww  .ja  va2 s .com*/
 * 
 * @param world
 * @param mapObject
 */
public Entity(GameWorld world, TextureMapObject mapObject) {
    this.world = world;

    /*
    TODO: I'm not entirely sure the positioning is accurate.  It might only work for 32x32 sprites in the level editor
    I'm also not sure why I have to add the texture height to the Y coordinate
    */
    this.spawnInWorld(
            mapObject.getX() / (this.world.getTiledMapUnitScale())
                    + (mapObject.getTextureRegion().getRegionWidth() / 32F),
            mapObject.getY() / (this.world.getTiledMapUnitScale())
                    + (mapObject.getTextureRegion().getRegionWidth() / 32F)
                    + (mapObject.getTextureRegion().getRegionWidth() / this.world.getTiledMapUnitScale()),
            0, 0);
}

From source file:rosthouse.rosty.loader.MapLoader.java

private void createTexture(TextureMapObject texture, PhysicsSystem physicsSystem, Entity mapObjectEntity,
        boolean isSensor) {
    SpriteComponent spriteComponent = new SpriteComponent(texture.getTextureRegion());
    PositionComponent positionComponent = new PositionComponent();

    float width = texture.getProperties().get("width", Float.class);
    float height = texture.getProperties().get("height", Float.class);
    float rotation = texture.getRotation();
    float x = texture.getX();
    float y = texture.getY() + height;

    String name = texture.getName();
    spriteComponent.sprite.setOrigin(texture.getOriginX() - width * 0.5f, texture.getOriginY() - height * 0.5f);
    spriteComponent.sprite.setSize(width, height);
    PolygonShape polygonShape = new PolygonShape();
    polygonShape.setAsBox(width * 0.5f, height * 0.5f, new Vector2(width * 0.5f, height * 0.5f),
            MathUtils.degreesToRadians * rotation);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.density = 0;//from w  w  w . j av  a  2 s.  com
    fixtureDef.friction = 1;
    fixtureDef.restitution = 0.2f;

    PhysicsComponent<PolygonShape> cmpSensor;
    if (isSensor) {
        cmpSensor = physicsSystem.createSensorComponent(BodyDef.BodyType.StaticBody, polygonShape,
                new Vector2(x, y), fixtureDef);
    } else {
        cmpSensor = physicsSystem.createPhysicsComponent(BodyDef.BodyType.StaticBody, polygonShape,
                new Vector2(x, y), fixtureDef);
    }
    cmpSensor.fixture.getBody().setTransform(x, y, MathUtils.degreesToRadians * rotation);
    mapObjectEntity.add(cmpSensor);
    cmpSensor.fixture.setUserData(mapObjectEntity.getId());
    mapObjectEntity.add(spriteComponent);
    mapObjectEntity.add(positionComponent);
}