Search in sources :

Example 26 with Rectangle

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

the class ScissorStack method pushScissors.

/** Pushes a new scissor {@link Rectangle} onto the stack, merging it with the current top of the stack. The minimal area of
	 * overlap between the top of stack rectangle and the provided rectangle is pushed onto the stack. This will invoke
	 * {@link GL20#glScissor(int, int, int, int)} with the final top of stack rectangle. In case no scissor is yet on the stack
	 * this will also enable {@link GL20#GL_SCISSOR_TEST} automatically.
	 * <p>
	 * Any drawing should be flushed before pushing scissors.
	 * @return true if the scissors were pushed. false if the scissor area was zero, in this case the scissors were not pushed and
	 *         no drawing should occur. */
public static boolean pushScissors(Rectangle scissor) {
    fix(scissor);
    if (scissors.size == 0) {
        if (scissor.width < 1 || scissor.height < 1)
            return false;
        Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
    } else {
        // merge scissors
        Rectangle parent = scissors.get(scissors.size - 1);
        float minX = Math.max(parent.x, scissor.x);
        float maxX = Math.min(parent.x + parent.width, scissor.x + scissor.width);
        if (maxX - minX < 1)
            return false;
        float minY = Math.max(parent.y, scissor.y);
        float maxY = Math.min(parent.y + parent.height, scissor.y + scissor.height);
        if (maxY - minY < 1)
            return false;
        scissor.x = minX;
        scissor.y = minY;
        scissor.width = maxX - minX;
        scissor.height = Math.max(1, maxY - minY);
    }
    scissors.add(scissor);
    HdpiUtils.glScissor((int) scissor.x, (int) scissor.y, (int) scissor.width, (int) scissor.height);
    return true;
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle)

Example 27 with Rectangle

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

the class SuperKoalio method getTiles.

private void getTiles(int startX, int startY, int endX, int endY, Array<Rectangle> tiles) {
    TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get("walls");
    rectPool.freeAll(tiles);
    tiles.clear();
    for (int y = startY; y <= endY; y++) {
        for (int x = startX; x <= endX; x++) {
            Cell cell = layer.getCell(x, y);
            if (cell != null) {
                Rectangle rect = rectPool.obtain();
                rect.set(x, y, 1, 1);
                tiles.add(rect);
            }
        }
    }
}
Also used : TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) Rectangle(com.badlogic.gdx.math.Rectangle) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)

Example 28 with Rectangle

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

the class Actor method clipBegin.

/** Clips the specified screen aligned rectangle, specified relative to the transform matrix of the stage's Batch. The
	 * transform matrix and the stage's camera must not have rotational components. Calling this method must be followed by a call
	 * to {@link #clipEnd()} if true is returned.
	 * @return false if the clipping area is zero and no drawing should occur.
	 * @see ScissorStack */
public boolean clipBegin(float x, float y, float width, float height) {
    if (width <= 0 || height <= 0)
        return false;
    Rectangle tableBounds = Rectangle.tmp;
    tableBounds.x = x;
    tableBounds.y = y;
    tableBounds.width = width;
    tableBounds.height = height;
    Stage stage = this.stage;
    Rectangle scissorBounds = Pools.obtain(Rectangle.class);
    stage.calculateScissors(tableBounds, scissorBounds);
    if (ScissorStack.pushScissors(scissorBounds))
        return true;
    Pools.free(scissorBounds);
    return false;
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle)

Example 29 with Rectangle

use of com.badlogic.gdx.math.Rectangle in project Alkahest-Coffee by AlkahestDev.

the class MainGame method create.

@Override
public void create() {
    Gdx.graphics.setCursor(Gdx.graphics.newCursor(new Pixmap(Gdx.files.internal("mouseCursorTemp.png")), 0, 0));
    assetManager = new AssetManager();
    queueLoading();
    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.translate(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    camera.update();
    //viewport = new FitViewport(1920, 1080, camera);
    fontCaches = new Array<BitmapFontCache>();
    BitmapFont dagger20 = new BitmapFont(Gdx.files.internal("fonts/dagger20.fnt"));
    BitmapFont dagger30 = new BitmapFont(Gdx.files.internal("fonts/dagger30.fnt"));
    BitmapFont dagger40 = new BitmapFont(Gdx.files.internal("fonts/dagger40.fnt"));
    BitmapFont dagger50 = new BitmapFont(Gdx.files.internal("fonts/dagger50.fnt"));
    dagger20.getData().markupEnabled = true;
    dagger30.getData().markupEnabled = true;
    dagger40.getData().markupEnabled = true;
    dagger50.getData().markupEnabled = true;
    fontCaches.add(new BitmapFontCache(dagger20));
    fontCaches.add(new BitmapFontCache(dagger30));
    fontCaches.add(new BitmapFontCache(dagger40));
    fontCaches.add(new BitmapFontCache(dagger50));
    shapeRenderer = new ShapeRenderer();
    gameMain = new MainMenu(fontCaches, assetManager, camera);
    loadingMenu = new LoadingMenu(fontCaches, assetManager, camera);
    connectingMenu = new ConnectingMenu(fontCaches, assetManager, camera);
    serverBrowser = new ServerBrowser(fontCaches, assetManager, camera);
    settingsMenu = new SettingsMenu(fontCaches, assetManager, camera);
    pickingInfoMenu = new ClientPickingInfoMenu(fontCaches, assetManager, camera);
    lobbyMenu = new ClientLobbyMenu(fontCaches, assetManager, camera);
    // loadingmenu is the only one that is setup before anything else is loaded, background frames are loaded and added to it here
    setupLoadingMenu();
    scW = Gdx.graphics.getWidth();
    scH = Gdx.graphics.getHeight();
    //System.out.println(new Pixmap(Gdx.files.internal("pixmapTest.png")).getPixel(0,0)>>8);//since gimp doesn't do alpha in a friendly way, I'll bitshift right 8 bits to ignore alpha
    state = GameState.State.LOADINGGAME;
    batch = new SpriteBatch();
    client = new MultiplayerClient();
    clientSoldier = new PlayerSoldier(new Rectangle(0, 0, 1, 2), 0, "");
    client.startClient();
    shapeRenderer.setProjectionMatrix(camera.combined);
    batch.setProjectionMatrix(camera.combined);
    menu = new UniversalClientMenu(fontCaches, assetManager, camera);
    Gdx.input.setInputProcessor(this);
}
Also used : MultiplayerClient(me.dumfing.multiplayerTools.MultiplayerClient) AssetManager(com.badlogic.gdx.assets.AssetManager) Rectangle(com.badlogic.gdx.math.Rectangle) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) PlayerSoldier(me.dumfing.multiplayerTools.PlayerSoldier) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 30 with Rectangle

use of com.badlogic.gdx.math.Rectangle in project Entitas-Java by Rubentxu.

the class DebugRendererSystem method render.

@Override
public void render() {
    // cam.update();
    batch.begin();
    Rectangle rect = new Rectangle(cam.position.x, cam.position.y, 3, 10);
    shapeRenderer.setProjectionMatrix(cam.combined);
    shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
    shapeRenderer.identity();
    shapeRenderer.translate(20, 12, 2);
    shapeRenderer.rotate(0, 0, 1, 90);
    shapeRenderer.rect(cam.position.x, cam.position.y, 50, 30);
    shapeRenderer.end();
    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    shapeRenderer.identity();
    shapeRenderer.translate(20, 12, 2);
    shapeRenderer.rotate(0, 0, 1, 90);
    shapeRenderer.rect(-rect.getX() / 2, -rect.getY() / 2, rect.width, rect.height);
    shapeRenderer.end();
    debugRenderer.render(physics, cam.combined);
    batch.end();
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle)

Aggregations

Rectangle (com.badlogic.gdx.math.Rectangle)35 Test (org.junit.Test)6 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)5 MockPointer (com.gemserk.commons.gdx.input.MockPointer)4 Circle (com.badlogic.gdx.math.Circle)3 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 Cell (com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 CoreEntity (com.ilargia.games.entitas.core.CoreEntity)2 View (com.ilargia.games.logicbrick.component.View)2 PlayerSoldier (me.dumfing.multiplayerTools.PlayerSoldier)2 FishColour (ca.hiphiparray.amazingmaze.FishCell.FishColour)1 AssetManager (com.badlogic.gdx.assets.AssetManager)1 FileHandle (com.badlogic.gdx.files.FileHandle)1 Camera (com.badlogic.gdx.graphics.Camera)1 Color (com.badlogic.gdx.graphics.Color)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Batch (com.badlogic.gdx.graphics.g2d.Batch)1 Glyph (com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph)1 TextBounds (com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds)1