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

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

Introduction

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

Prototype

public float getOriginY() 

Source Link

Usage

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   www .  ja  v  a 2 s .  co m
    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);
}