Search in sources :

Example 76 with Vector2

use of com.badlogic.gdx.math.Vector2 in project libgdx by libgdx.

the class Group method hit.

public Actor hit(float x, float y, boolean touchable) {
    if (touchable && getTouchable() == Touchable.disabled)
        return null;
    Vector2 point = tmp;
    Actor[] childrenArray = children.items;
    for (int i = children.size - 1; i >= 0; i--) {
        Actor child = childrenArray[i];
        if (!child.isVisible())
            continue;
        child.parentToLocalCoordinates(point.set(x, y));
        Actor hit = child.hit(point.x, point.y, touchable);
        if (hit != null)
            return hit;
    }
    return super.hit(x, y, touchable);
}
Also used : Vector2(com.badlogic.gdx.math.Vector2)

Example 77 with Vector2

use of com.badlogic.gdx.math.Vector2 in project libgdx by libgdx.

the class Image method layout.

public void layout() {
    if (drawable == null)
        return;
    float regionWidth = drawable.getMinWidth();
    float regionHeight = drawable.getMinHeight();
    float width = getWidth();
    float height = getHeight();
    Vector2 size = scaling.apply(regionWidth, regionHeight, width, height);
    imageWidth = size.x;
    imageHeight = size.y;
    if ((align & Align.left) != 0)
        imageX = 0;
    else if ((align & Align.right) != 0)
        imageX = (int) (width - imageWidth);
    else
        imageX = (int) (width / 2 - imageWidth / 2);
    if ((align & Align.top) != 0)
        imageY = (int) (height - imageHeight);
    else if ((align & Align.bottom) != 0)
        imageY = 0;
    else
        imageY = (int) (height / 2 - imageHeight / 2);
}
Also used : Vector2(com.badlogic.gdx.math.Vector2)

Example 78 with Vector2

use of com.badlogic.gdx.math.Vector2 in project libgdx by libgdx.

the class Box2DCharacterControllerTest method createEdge.

private Body createEdge(BodyType type, float x1, float y1, float x2, float y2, float density) {
    BodyDef def = new BodyDef();
    def.type = type;
    Body box = world.createBody(def);
    EdgeShape poly = new EdgeShape();
    poly.set(new Vector2(0, 0), new Vector2(x2 - x1, y2 - y1));
    box.createFixture(poly, density);
    box.setTransform(x1, y1, 0);
    poly.dispose();
    return box;
}
Also used : EdgeShape(com.badlogic.gdx.physics.box2d.EdgeShape) Vector2(com.badlogic.gdx.math.Vector2) BodyDef(com.badlogic.gdx.physics.box2d.BodyDef) Body(com.badlogic.gdx.physics.box2d.Body)

Example 79 with Vector2

use of com.badlogic.gdx.math.Vector2 in project libgdx by libgdx.

the class Box2DCharacterControllerTest method createPlayer.

private Body createPlayer() {
    BodyDef def = new BodyDef();
    def.type = BodyType.DynamicBody;
    Body box = world.createBody(def);
    PolygonShape poly = new PolygonShape();
    poly.setAsBox(0.45f, 1.4f);
    playerPhysicsFixture = box.createFixture(poly, 1);
    poly.dispose();
    CircleShape circle = new CircleShape();
    circle.setRadius(0.45f);
    circle.setPosition(new Vector2(0, -1.4f));
    playerSensorFixture = box.createFixture(circle, 0);
    circle.dispose();
    box.setBullet(true);
    return box;
}
Also used : PolygonShape(com.badlogic.gdx.physics.box2d.PolygonShape) CircleShape(com.badlogic.gdx.physics.box2d.CircleShape) Vector2(com.badlogic.gdx.math.Vector2) BodyDef(com.badlogic.gdx.physics.box2d.BodyDef) Body(com.badlogic.gdx.physics.box2d.Body)

Example 80 with Vector2

use of com.badlogic.gdx.math.Vector2 in project libgdx by libgdx.

the class PathTest method create.

@Override
public void create() {
    renderer = new ImmediateModeRenderer20(false, false, 0);
    spriteBatch = new SpriteBatch();
    obj = new Sprite(new Texture(Gdx.files.internal("data/badlogicsmall.jpg")));
    obj.setSize(40, 40);
    obj.setOriginCenter();
    obj2 = new Sprite(new Texture(Gdx.files.internal("data/bobrgb888-32x32.png")));
    obj2.setSize(40, 40);
    obj2.setOriginCenter();
    // 96DP
    ZIGZAG_SCALE = Gdx.graphics.getDensity() * 96;
    float w = Gdx.graphics.getWidth() - obj.getWidth();
    float h = Gdx.graphics.getHeight() - obj.getHeight();
    paths.add(new Bezier<Vector2>(new Vector2(0, 0), new Vector2(w, h)));
    paths.add(new Bezier<Vector2>(new Vector2(0, 0), new Vector2(0, h), new Vector2(w, h)));
    paths.add(new Bezier<Vector2>(new Vector2(0, 0), new Vector2(w, 0), new Vector2(0, h), new Vector2(w, h)));
    Vector2[] cp = new Vector2[] { new Vector2(0, 0), new Vector2(w * 0.25f, h * 0.5f), new Vector2(0, h), new Vector2(w * 0.5f, h * 0.75f), new Vector2(w, h), new Vector2(w * 0.75f, h * 0.5f), new Vector2(w, 0), new Vector2(w * 0.5f, h * 0.25f) };
    paths.add(new BSpline<Vector2>(cp, 3, true));
    paths.add(new CatmullRomSpline<Vector2>(cp, true));
    pathLength = paths.get(currentPath).approxLength(500);
    avg_speed = speed * pathLength;
    Gdx.input.setInputProcessor(this);
}
Also used : ImmediateModeRenderer20(com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Vector2(com.badlogic.gdx.math.Vector2) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Aggregations

Vector2 (com.badlogic.gdx.math.Vector2)103 Body (com.badlogic.gdx.physics.box2d.Body)21 BodyDef (com.badlogic.gdx.physics.box2d.BodyDef)14 FixtureDef (com.badlogic.gdx.physics.box2d.FixtureDef)10 PolygonShape (com.badlogic.gdx.physics.box2d.PolygonShape)10 Texture (com.badlogic.gdx.graphics.Texture)7 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)7 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)7 EdgeShape (com.badlogic.gdx.physics.box2d.EdgeShape)7 Vector3 (com.badlogic.gdx.math.Vector3)6 Fixture (com.badlogic.gdx.physics.box2d.Fixture)6 World (com.badlogic.gdx.physics.box2d.World)6 GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)6 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)5 CircleShape (com.badlogic.gdx.physics.box2d.CircleShape)5 Test (org.junit.Test)5 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)4 Box2DDebugRenderer (com.badlogic.gdx.physics.box2d.Box2DDebugRenderer)4 Contact (com.badlogic.gdx.physics.box2d.Contact)4 WorldManifold (com.badlogic.gdx.physics.box2d.WorldManifold)4