Java Code Examples for com.badlogic.gdx.graphics.g2d.Batch#end()

The following examples show how to use com.badlogic.gdx.graphics.g2d.Batch#end() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridRenderer.java    From talos with Apache License 2.0 6 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	super.draw(batch, parentAlpha);
	batch.end();

	shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());

	final float worldWidth = stage.getViewport().getWorldWidth() * camera.zoom;
	final float worldHeight = stage.getViewport().getWorldHeight() * camera.zoom;

	final Vector3 position = stage.getViewport().getCamera().position;

	float x = position.x - worldWidth / 2f;
	float y = position.y - worldHeight / 2f;

	shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
	drawGrid(x, y, worldWidth, worldHeight);
	shapeRenderer.end();

	batch.begin();
}
 
Example 2
Source File: ShapeWidget.java    From talos with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    tmp.set(0, 0);
    localToStageCoordinates(tmp);

    drawBg(batch, parentAlpha);

    batch.end();
    shapeRenderer.setProjectionMatrix(getStage().getCamera().combined);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    shapeRenderer.begin(ShapeRenderer.ShapeType.Line);

    drawGrid(batch, parentAlpha);
    drawShape(batch, parentAlpha);
    drawTools(batch, parentAlpha);

    shapeRenderer.end();
    batch.begin();

}
 
Example 3
Source File: BvBWorkspace.java    From talos with Apache License 2.0 6 votes vote down vote up
@Override
public void drawContent(Batch batch, float parentAlpha) {
    batch.end();
    drawGrid(batch, parentAlpha);
    batch.begin();

    drawVFXBefore(batch, parentAlpha);
    drawSpine(batch, parentAlpha);
    drawVFX(batch, parentAlpha);


    drawTools(batch, parentAlpha);

    if(showingTools) {
        topUI.draw(batch, parentAlpha);
    }
}
 
Example 4
Source File: BvBWorkspace.java    From talos with Apache License 2.0 6 votes vote down vote up
private void drawTools(Batch batch, float parentAlpha) {
    Skeleton skeleton = skeletonContainer.getSkeleton();
    if(skeleton == null) return;

    if(showingTools) {
        batch.end();
        Gdx.gl.glLineWidth(1f);
        Gdx.gl.glEnable(GL20.GL_BLEND);
        shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);

        drawShapeRendererTools();

        shapeRenderer.end();
        batch.begin();

        if(showingTools) {
            drawSpriteTools(batch, parentAlpha);
        }
    }
}
 
Example 5
Source File: GradientDrawable.java    From skin-composer with MIT License 6 votes vote down vote up
@Override
public void draw(Batch batch, float x, float y, float width, float height) {
    float[] alphas = {col1.a, col2.a, col3.a, col4.a};
    col1.a = batch.getColor().a * col1.a;
    col2.a = batch.getColor().a * col2.a;
    col3.a = batch.getColor().a * col3.a;
    col4.a = batch.getColor().a * col4.a;
    
    g.begin(ShapeRenderer.ShapeType.Filled);
    g.setProjectionMatrix(batch.getProjectionMatrix());
    g.setTransformMatrix(batch.getTransformMatrix());
    batch.end();
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    g.rect(x + borderLeft, y + borderBottom, width - borderLeft - borderRight, height - borderBottom - borderTop, col1, col2, col3, col4);
    g.end();
    Gdx.gl.glDisable(GL20.GL_BLEND);
    batch.begin();
    
    col1.a = alphas[0];
    col2.a = alphas[1];
    col3.a = alphas[2];
    col4.a = alphas[3];
}
 
Example 6
Source File: ColorFadeTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@Override
public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float percent) {
	float width = currentScreenTexture.getWidth();
	float height = currentScreenTexture.getHeight();
	float x = 0;
	float y = 0;

	if (interpolation != null) percent = interpolation.apply(percent);

	batch.begin();

	float fade = percent * 2;

	if (fade > 1.0f) {
		fade = 1.0f - (percent * 2 - 1.0f);
		color.a = 1.0f - fade;
		batch.setColor(color);

		batch.draw(nextScreenTexture, 0, 0, width / 2, height / 2, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(),
			1, 1, 0, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), false, true);

	} else {

		color.a = 1.0f - fade;
		batch.setColor(color);

		batch.draw(currentScreenTexture, 0, 0, width / 2, height / 2, width, height, 1, 1, 0, 0, 0, (int)width, (int)height,
			false, true);

	}

	color.a = fade;

	batch.setColor(color);
	batch.draw(texture, 0, 0, width, height);
	batch.end();
	batch.setColor(Color.WHITE);

}
 
Example 7
Source File: AlphaFadingTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@Override
public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float alpha) {
	alpha = Interpolation.fade.apply(alpha);
	batch.begin();
	batch.setColor(1, 1, 1, 1);
	batch.draw(currentScreenTexture, 0, 0, 0, 0, currentScreenTexture.getWidth(), currentScreenTexture.getHeight(), 1, 1, 0, 0,
		0, currentScreenTexture.getWidth(), currentScreenTexture.getHeight(), false, true);
	batch.setColor(1, 1, 1, alpha);
	batch.draw(nextScreenTexture, 0, 0, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), 1, 1, 0, 0, 0,
		nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), false, true);
	batch.end();

}
 
Example 8
Source File: SlidingTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@Override
public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float percent) {
	float width = currentScreenTexture.getWidth();
	float height = currentScreenTexture.getHeight();
	float x = 0;
	float y = 0;
	if (interpolation != null) percent = interpolation.apply(percent);

	switch (direction) {
	case LEFT:
		x = -width * percent;
		if (!slideOut) x += width;
		break;
	case RIGHT:
		x = width * percent;
		if (!slideOut) x -= width;
		break;
	case UP:
		y = height * percent;
		if (!slideOut) y -= height;
		break;
	case DOWN:
		y = -height * percent;
		if (!slideOut) y += height;
		break;
	}
	Texture texBottom = slideOut ? nextScreenTexture : currentScreenTexture;
	Texture texTop = slideOut ? currentScreenTexture : nextScreenTexture;

	batch.begin();
	batch.draw(texBottom, 0, 0, 0, 0, width, height, 1, 1, 0, 0, 0, (int)width, (int)height, false, true);
	batch.draw(texTop, x, y, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), 1, 1, 0, 0, 0,
		nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), false, true);
	batch.end();

}
 
Example 9
Source File: SlicingTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@Override
public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float percent) {
	float width = currentScreenTexture.getWidth();
	float height = currentScreenTexture.getHeight();
	float x = 0;
	float y = 0;
	int sliceWidth = (int)(width / slices.size);

	batch.begin();
	batch.draw(currentScreenTexture, 0, 0, 0, 0, width, height, 1, 1, 0, 0, 0, (int)width, (int)height, false, true);
	if (interpolation != null) percent = interpolation.apply(percent);
	for (int i = 0; i < slices.size; i++) {

		x = i * sliceWidth;

		float offsetY = height * (1 + slices.get(i) / (float)slices.size);
		switch (direction) {
		case UP:
			y = -offsetY + offsetY * percent;
			break;
		case DOWN:
			y = offsetY - offsetY * percent;
			break;
		case UPDOWN:
			if (i % 2 == 0) {
				y = -offsetY + offsetY * percent;
			} else {
				y = offsetY - offsetY * percent;
			}
			break;
		}
		batch.draw(nextScreenTexture, x, y, 0, 0, sliceWidth, nextScreenTexture.getHeight(), 1, 1, 0, i * sliceWidth, 0,
			sliceWidth, nextScreenTexture.getHeight(), false, true);
	}
	batch.end();
}
 
Example 10
Source File: SceneList.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public TextureRegion getBgIcon(String atlas, String region) {

		// check here for dispose instead in project loading because the opengl
		// context lost in new project thread
		if (disposeBgCache) {
			dispose();
			disposeBgCache = false;
		}

		String s = atlas + "#" + region;
		TextureRegion icon = bgIconCache.get(s);

		if (icon == null) {
			Batch batch = getStage().getBatch();
			batch.end();

			try {
				icon = createBgIcon(atlas, region);
			} catch (Exception e) {
				EditorLogger.error("Error creating Background icon: " + atlas + "." + region);
			}

			if (icon == null) {
				EditorLogger.error("Error creating Background icon: " + atlas + "." + region);
				icon = Ctx.assetManager.getIcon("ic_no_scene");
			}

			bgIconCache.put(s, icon);

			batch.begin();

		}

		return icon;
	}
 
Example 11
Source File: FontMetricsTool.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void render() {
  Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

  stage.act();
  stage.draw();

  Batch b = stage.getBatch();
  b.begin();
  GlyphLayout consolas16Layout = Riiablo.fonts.consolas16.draw(b, STRING, 0, 550, 600, center ? Align.center : Align.left, true);
  b.end();

  PaletteIndexedBatch batch = Riiablo.batch;
  batch.begin(Riiablo.palettes.units);
  batch.setBlendMode(active.getBlendMode());
  GlyphLayout otherLayout = active.draw(batch, STRING, 0, 250, 600, center ? Align.center : Align.left, true);
  batch.end();

  if (debug) {
    ShapeRenderer shapes = Riiablo.shapes;
    shapes.begin(ShapeRenderer.ShapeType.Line);
    drawDebug(Riiablo.fonts.consolas16, consolas16Layout, 550);
    drawDebug(active, otherLayout, 250);
    shapes.end();
  }
}
 
Example 12
Source File: Rain.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void draw(Batch batch, float parentAlpha) {
    validate();
    batch.end();
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    ShapeRenderer renderer = Config.shapeRenderer;
    renderer.setProjectionMatrix(batch.getProjectionMatrix());
    renderer.setTransformMatrix(batch.getTransformMatrix());

    renderer.begin(ShapeRenderer.ShapeType.Filled);
    renderer.setColor(style.color.r, style.color.g, style.color.b, style.color.a * parentAlpha);
    float usedWidth = getWidth() - style.pad;
    int count = (int) (usedWidth / (style.dropWidth + style.pad));
    if (count == 0)
        return;
    float step = usedWidth / ((float) count);
    float x = style.pad;
    for (int i = 0, n = rows.size; i < n; i++) {
        Row row = rows.get(i);
        drawRow(x, row);
        x += step;
    }
    renderer.end();
    Gdx.gl.glDisable(GL20.GL_BLEND);
    batch.begin();
}
 
Example 13
Source File: StorageDownloadImageTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch) {
    if (img == null) return;
    batch.begin();
    batch.draw(img, 0, 0);
    batch.end();
}
 
Example 14
Source File: BadlogicTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch) {
    if (img == null) return;
    batch.begin();
    batch.draw(img, 0, 0);
    batch.end();
}
 
Example 15
Source File: CustomizeScreen.java    From Klooni1010 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void render(float delta) {
    Klooni.theme.glClearBackground();
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    stage.act(Math.min(Gdx.graphics.getDeltaTime(), MIN_DELTA));
    stage.draw();

    // After everything is drawn, showcase the current shop item
    SnapshotArray<Actor> children = shopGroup.getChildren();
    if (children.size > 0) {
        final ShopCard card = (ShopCard) children.get(showcaseIndex);

        final Batch batch = stage.getBatch();
        batch.begin();
        // For some really strange reason, we need to displace the particle effect
        // by "buyBand.height", or it will render exactly that height below where
        // it should.
        // TODO Fix this - maybe use the same project matrix as stage.draw()?
        // batch.setProjectionMatrix(stage.getViewport().getCamera().combined)
        if (!card.showcase(batch, buyBand.getHeight())) {
            showcaseIndex = (showcaseIndex + 1) % children.size;
        }
        batch.end();
    }

    if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)) {
        goBack();
    }
}
 
Example 16
Source File: AnimationTool.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void render() {
  Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

  stage.act();
  stage.draw();

  float delta = Gdx.graphics.getDeltaTime();
  if (lockFps) {
    accumulator += delta;
    while (accumulator >= Animation.FRAME_DURATION) {
      lastUpdate = accumulator;
      accumulator -= Animation.FRAME_DURATION;
      anim.act(Animation.FRAME_DURATION);
    }
  } else {
    lastUpdate = delta;
    anim.act(delta);
  }

  Batch b = stage.getBatch();
  b.begin();
  Riiablo.fonts.consolas16.draw(b, String.valueOf(Gdx.graphics.getFramesPerSecond()), 0, Gdx.graphics.getHeight());
  Riiablo.fonts.consolas16.draw(b, String.valueOf(MathUtils.roundPositive(1 / lastUpdate)), 0, Gdx.graphics.getHeight() - 16);
  b.end();

  Riiablo.batch.begin(Riiablo.palettes.act1);
  anim.draw(Riiablo.batch, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
  Riiablo.batch.end();
}
 
Example 17
Source File: ModuleBoardWidget.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    batch.end();
    shapeRenderer.setProjectionMatrix(getStage().getCamera().combined);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    drawCurves();
    shapeRenderer.end();
    batch.begin();

    super.draw(batch, parentAlpha);
}
 
Example 18
Source File: CurveWidget.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    width = getWidth() - 4f;
    height = getHeight() - 4f;

    Drawable backgroundFrame = getSkin().getDrawable("white");
    batch.setColor(Color.BLACK);
    backgroundFrame.draw(batch, getX(), getY(), getWidth(), getHeight());

    batch.setColor(bgColor);
    Drawable background = getSkin().getDrawable("white");
    background.draw(batch, getX()+1, getY()+1, getWidth()-2, getHeight()-2.5f);

    /// Shape renderer stuff

    batch.end();
    shapeRenderer.setProjectionMatrix(getStage().getCamera().combined);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);

    drawLegend();

    drawCurve(batch, parentAlpha);

    shapeRenderer.end();
    batch.begin();
}
 
Example 19
Source File: PreviewWidget.java    From talos with Apache License 2.0 4 votes vote down vote up
@Override
public void drawContent(Batch batch, float parentAlpha) {
    batch.end();
    drawGrid(batch, parentAlpha * 0.5f);
    batch.begin();

    mid.set(0, 0);

    float imagePrefWidth = previewImage.getPrefWidth();
    float imagePrefHeight = previewImage.getPrefHeight();
    float scale = imagePrefHeight / imagePrefWidth;

    float imageWidth = previewController.getImageWidth();
    float imageHeight = imageWidth * scale;
    previewController.getPreviewBoxWidth();

    previewImage.setPosition(mid.x - imageWidth / 2, mid.y - imageHeight / 2);
    previewImage.setSize(imageWidth, imageHeight);
    if (previewController.isBackground()) {
        previewImage.draw(batch, parentAlpha);
    }

    spriteBatchParticleRenderer.setBatch(batch);

    batch.flush();
    glProfiler.enable();

    long timeBefore = TimeUtils.nanoTime();

    final ParticleEffectInstance particleEffect = TalosMain.Instance().TalosProject().getParticleEffect();
    particleEffect.render(particleRenderer);

    batch.flush();
    renderTime.put(TimeUtils.timeSinceNanos(timeBefore));
    trisCount = (int) (glProfiler.getVertexCount().value / 3f);
    glProfiler.disable();


    if (!previewController.isBackground()) {
        previewImage.draw(batch, parentAlpha);
    }

    // now for the drag points
    if(dragPoints.size > 0) {
        batch.end();
        tmpColor.set(Color.ORANGE);
        tmpColor.a = 0.8f;
        Gdx.gl.glLineWidth(1f);
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
        shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
        shapeRenderer.setColor(tmpColor);

        for (DragPoint point : dragPoints) {
            shapeRenderer.circle(point.position.x, point.position.y, 0.1f * camera.zoom, 15);
        }

        shapeRenderer.end();
        batch.begin();
    }
}
 
Example 20
Source File: VfxWidgetGroup.java    From gdx-vfx with Apache License 2.0 4 votes vote down vote up
@Override
    public void draw(Batch batch, float parentAlpha) {
        validate();

//        //TODO Check if there are any active effects before start capturing/processing.
//        if (!vfxManager.anyEnabledEffects()) {
//            this.drawChildren(batch, parentAlpha);
//            return;
//        }

        VfxFrameBuffer captureBuffer = vfxManager.getResultBuffer();

        batch.end();

        performPendingResize();

        vfxManager.cleanUpBuffers();

        captureBuffer.addRenderer(rendererAdapter);
        vfxManager.beginInputCapture();

        batch.begin();

        validate();
        drawChildren(batch, parentAlpha);

        batch.end();

        vfxManager.endInputCapture();
        captureBuffer.removeRenderer(rendererAdapter);

        vfxManager.applyEffects();

        batch.begin();

        // Render result to the screen.
        Color color = getColor();
        batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
        batch.draw(vfxManager.getResultBuffer().getFbo().getColorBufferTexture(),
                getX(), getY(), getWidth(), getHeight(),
                0f, 0f, 1f, 1f);
    }