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;
}
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);
}
}
}
}
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;
}
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);
}
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();
}
Aggregations