com.badlogic.gdx.graphics.g2d.Batch Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g2d.Batch. 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: ChatActor.java    From Cubes with MIT License 6 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
  validate();

  Color color = getColor();
  batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);

  float currentY = getItemHeight();
  for (ChatMessage item : items) {
    if (open.isDisabled()) {
      long ms = System.currentTimeMillis() - item.timeReceived;
      font.getColor().a = ms < FADE_MSG_MS ? 1 : 1f - (((float) (ms - FADE_MSG_MS)) / (HIDE_MSG_MS - FADE_MSG_MS));
    }

    font.draw(batch, item.toString(), getX(), getY() + currentY);
    currentY += itemHeight;
  }

  font.getColor().a = 1;
}
 
Example #2
Source File: ThemeCard.java    From Klooni1010 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    final float x = getX(), y = getY();

    batch.setColor(theme.background);
    batch.draw(background, x, y, getWidth(), getHeight());

    // Avoid drawing on the borders by adding +1 cell padding
    for (int i = 0; i < colorsUsed.length; ++i) {
        for (int j = 0; j < colorsUsed[i].length; ++j) {
            Cell.draw(theme.cellTexture, theme.getCellColor(colorsUsed[i][j]), batch,
                    x + cellSize * (j + 1), y + cellSize * (i + 1), cellSize);
        }
    }

    super.draw(batch, parentAlpha);
}
 
Example #3
Source File: ControlPanel.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Batch batch, float a) {
  final float x = getX();
  final float y = getY();
  batch.draw(background, x, y);
  batch.draw(health,  x + 30, y + 14);
  batch.draw(overlay, x + 28, y +  6);
  super.draw(batch, a);
  if (label.isVisible()) {
    label.setX(getX());
    label.setText(Riiablo.string.format("panelhealth",
        (int) Riiablo.charData.getStats().get(Stat.hitpoints).toFloat(),
        (int) Riiablo.charData.getStats().get(Stat.maxhp).toFloat()));
    label.draw(batch, a);
  }
}
 
Example #4
Source File: EffectCard.java    From Klooni1010 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean showcase(Batch batch, float yDisplacement) {
    board.pos.y += yDisplacement;

    // If no effect is running
    if (board.effectsDone()) {
        // And we want to create a new one
        if (needCreateEffect) {
            // Clear at cells[1][1], the center one
            board.clearAll(1, 1, effect);
            needCreateEffect = false;
        } else {
            // Otherwise, the previous effect finished, so return false because we're done
            // We also want to draw the next time so set the flag to true
            setRandomPiece();
            needCreateEffect = true;
            return false;
        }
    }

    board.draw(batch);
    return true;
}
 
Example #5
Source File: RenderWidget.java    From Mundus with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    if (renderer == null || cam == null) return;

    // render part of the ui & pause rest
    batch.end();

    vec.set(getOriginX(), getOriginY());
    vec = localToStageCoordinates(vec);
    final int width = (int) getWidth();
    final int height = (int) getHeight();

    // apply widget viewport
    viewport.setScreenBounds((int) vec.x, (int) vec.y, width, height);
    viewport.setWorldSize(width * viewport.getUnitsPerPixel(), height * viewport.getUnitsPerPixel());
    viewport.apply();

    // render 3d scene
    renderer.render(cam);

    // re-apply stage viewport
    UI.INSTANCE.getViewport().apply();

    // proceed ui rendering
    batch.begin();
}
 
Example #6
Source File: VisImageTextButton.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	updateImage();
	Color fontColor;
	if (isDisabled() && style.disabledFontColor != null)
		fontColor = style.disabledFontColor;
	else if (isPressed() && style.downFontColor != null)
		fontColor = style.downFontColor;
	else if (isChecked() && style.checkedFontColor != null)
		fontColor = (isOver() && style.checkedOverFontColor != null) ? style.checkedOverFontColor : style.checkedFontColor;
	else if (isOver() && style.overFontColor != null)
		fontColor = style.overFontColor;
	else
		fontColor = style.fontColor;
	if (fontColor != null) label.getStyle().fontColor = fontColor;
	super.draw(batch, parentAlpha);
	if (focusBorderEnabled && drawBorder && style.focusBorder != null)
		style.focusBorder.draw(batch, getX(), getY(), getWidth(), getHeight());
}
 
Example #7
Source File: Debris.java    From libgdx-demo-pax-britannica with MIT License 6 votes vote down vote up
@Override
public void draw(Batch batch) {
	super.draw(batch);

	delta = Math.min(0.06f, Gdx.graphics.getDeltaTime());

	since_alive += delta;

	facing.rotate((SPEED + random_speed) * delta).nor();
	position.add(facing.scl((SPEED + random_speed) * delta));
	this.setPosition(position.x, position.y);

	if (since_alive < FADE_TIME) {
		super.setColor(1, 1, 1, Math.min((since_alive / FADE_TIME) * random_opacity, random_opacity));
	} else {
		this.setColor(1, 1, 1, Math.min(1 - (since_alive - LIFETIME + FADE_TIME) / FADE_TIME, 1) * random_opacity);
	}
	if (since_alive > LIFETIME) {
		alive = false;
		this.setColor(1, 1, 1, 0);
	}
}
 
Example #8
Source File: NinePatchWidget.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) {
    if (widget.zoom == 1) {
        style.lightTile.draw(batch, x, y, width, height);
    } else {
        drawTiles(batch, x, y, width, height);
    }
    
    if (drawable != null) {
        drawDrawable(batch, x, y, width, height);
    }
    
    drawHandles(batch, x, y, width, height);
    
    drawBlackBars(batch, x, y, width, height);
    
    drawGrid(batch, x, y, width, height);
    
    drawBorder(batch, x, y, width, height);
}
 
Example #9
Source File: AnimationSubView.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override public void draw(Batch batch, float parentAlpha) {
    if (regions.size <= 0)
        return;
    GdxHelper.setBatchColor(batch, getColor(), parentAlpha);
    TextureRegion region = animation.getKeyFrame(stateTime);
    float rotation = getRotation();
    if (rotation != 0) {
        batch.draw(
            region,
            getX(),
            getY(),
            getOriginX(),
            getOriginY(),
            region.getRegionWidth(),
            region.getRegionHeight(),
            1,
            1,
            rotation
        );
    } else {
        batch.draw(region, getX(), getY(), region.getRegionWidth(), region.getRegionHeight());
    }
}
 
Example #10
Source File: PolylineRenderer.java    From talos with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Batch batch, float x, float y, float width, float height, float rotation) {
    Polyline polyline = polyline();
    polyline.set(width, rotation);
    polyline.draw(batch, region, x, y);

    tmpArr.clear();
    for(Particle key: polylineMap.keys()) {
        if(key.alpha == 1f) {
            tmpArr.add(key);
        }
    }
    for(int i = 0; i < tmpArr.size; i++) {
        if(polylineMap.containsKey(tmpArr.get(i))) {
            polylinePool.free(polylineMap.get(tmpArr.get(i)));
        }
        polylineMap.remove(tmpArr.get(i));
    }
}
 
Example #11
Source File: Fish.java    From libgdx-demo-pax-britannica with MIT License 6 votes vote down vote up
@Override
public void draw(Batch batch) {
	super.draw(batch);
	
	delta = Math.min(0.06f, Gdx.graphics.getDeltaTime());
	
	since_alive += delta/2.f;
	position.add((SPEED + random_speed) * delta * 5.f*random_direction,0);
	this.setPosition(position.x, position.y);

	
	if (since_alive < FADE_TIME) {
		super.setColor(1, 1, 1, Math.min((since_alive / FADE_TIME)*random_opacity,random_opacity));
	} else {
		this.setColor(1, 1, 1, Math.min(1 - (since_alive - LIFETIME + FADE_TIME) / FADE_TIME, 1) * random_opacity);
	}
	if (since_alive > LIFETIME) {
		alive = false;
	}
}
 
Example #12
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 #13
Source File: E2ETestRunnerImpl.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Override
public void render(Batch batch) {
    if (tests.size == 0) return;
    tests.peek().update(MathUtils.clamp(0, 0.2f, Gdx.graphics.getDeltaTime()));
    Gdx.gl.glClearColor(1, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    tests.peek().draw(batch);
    checkTestsStates();
    state += Gdx.graphics.getDeltaTime();
}
 
Example #14
Source File: LinkLabel.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	super.draw(batch, parentAlpha);
	Drawable underline = style.underline;
	if (underline != null && clickListener.isOver()) {
		Color color = tempColor.set(getColor());
		color.a *= parentAlpha;
		if (style.fontColor != null) color.mul(style.fontColor);
		batch.setColor(color);
		underline.draw(batch, getX(), getY(), getWidth(), 1);
	}
}
 
Example #15
Source File: VisImageButton.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	updateImage();
	super.draw(batch, parentAlpha);
	if (focusBorderEnabled && drawBorder && style.focusBorder != null)
		style.focusBorder.draw(batch, getX(), getY(), getWidth(), getHeight());
}
 
Example #16
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 #17
Source File: BorderAreaDim.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    Color col = getColor();
    batch.setColor(col.r, col.g, col.b, col.a * parentAlpha);

    drawable.draw(batch, getX(), getY(), getWidth(), actor.getY());
    drawable.draw(batch, getX(), getY() + actor.getY() + actor.getHeight(), getWidth(), getHeight() - (actor.getY() + actor.getHeight()));
    drawable.draw(batch, getX(), getY() + actor.getY(), actor.getX(), actor.getHeight());
    drawable.draw(batch, getX() + (actor.getX() + actor.getWidth()), getY() + actor.getY(), getWidth() - (actor.getX() + actor.getWidth()), actor.getHeight());
}
 
Example #18
Source File: Label.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float a) {
  if (batch instanceof PaletteIndexedBatch) {
    draw((PaletteIndexedBatch) batch, a);
  } else {
    throw new GdxRuntimeException("Not supported");
  }
}
 
Example #19
Source File: BvBWorkspace.java    From talos with Apache License 2.0 5 votes vote down vote up
private void drawVFX(Batch batch, float parentAlpha) {
    Skeleton skeleton = skeletonContainer.getSkeleton();
    if(skeleton == null) return;

    talosRenderer.setBatch(batch);
    for(BoundEffect effect: skeletonContainer.getBoundEffects()) {
        if(effect.isBehind()) continue;
        for(ParticleEffectInstance particleEffectInstance: effect.getParticleEffects()) {
            talosRenderer.render(particleEffectInstance);
        }
    }
}
 
Example #20
Source File: PatchedVisTextField.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawText(Batch batch, BitmapFont font, float x, float y) {
	//PATCH: Disabled color markup for BitmapFont when updating GlyphLayout https://github.com/libgdx/libgdx/issues/4576
	BitmapFontData fontData = font.getData();
	boolean markupEnabled = fontData.markupEnabled;
	fontData.markupEnabled = false;
	super.drawText(batch, font, x, y);
	fontData.markupEnabled = markupEnabled;
}
 
Example #21
Source File: Score.java    From martianrun with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    if (getScore() == 0) {
        return;
    }
    font.drawWrapped(batch, String.format("%d", getScore()), bounds.x, bounds.y, bounds.width, BitmapFont.HAlignment.RIGHT);
}
 
Example #22
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 #23
Source File: FilteredTree.java    From talos with Apache License 2.0 5 votes vote down vote up
public void draw (Batch batch, float parentAlpha) {
    Color color = getColor();
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    if (style.background != null)
        style.background.draw(batch, getX(), getY(), getWidth(), getHeight());
    draw(batch, rootNodes, leftColumnWidth);
    super.draw(batch, parentAlpha); // Draw actors.
}
 
Example #24
Source File: ItemGrid.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
  PaletteIndexedBatch b = (PaletteIndexedBatch) batch;
  b.setBlendMode(BlendMode.SOLID, clickListener.isOver() && itemData.getCursor() == null ? backgroundColorG : backgroundColorB);
  b.draw(fill, getX(), getY(), getWidth(), getHeight());
  b.resetBlendMode();
  item.draw(b, 1);
  if (clickListener.isOver() && itemData.getCursor() == null) {
    Riiablo.game.setDetails(item.details(), item, ItemGrid.this, item);
  }
}
 
Example #25
Source File: GdxHelper.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static void showStageEvents(final Stage stage) {
    EventListener listener = new EventListener() {
        private final Vector2 tmp = new Vector2();
        private Actor actor = new Actor() {
            @Override public void draw(Batch batch, float parentAlpha) {
                if (target == null)
                    return;
                batch.end();
                Config.shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
                Config.shapeRenderer.setProjectionMatrix(stage.getCamera().combined);
                Gdx.gl.glLineWidth(6);
                Config.shapeRenderer.setColor(Color.ORANGE);
                Vector2 pos = target.localToStageCoordinates(tmp.set(0, 0));
                float x = pos.x, y = pos.y;
                Vector2 top = target.localToStageCoordinates(tmp.set(target.getWidth(), target.getHeight()));
                float maxX = top.x, maxY = top.y;
                Config.shapeRenderer.rect(x, y, maxX - x, maxY - y);

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

        {
            stage.addActor(actor);
        }

        public Actor target;

        @Override public boolean handle(Event event) {
            target = event.getTarget();
            return false;
        }
    };
    stage.addListener(listener);
}
 
Example #26
Source File: ScrollPane.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	if (widget == null) return;

	validate();

	// Setup transform for this group.
	applyTransform(batch, computeTransform());

	if (scrollX) hKnobBounds.x = hScrollBounds.x + (int)((hScrollBounds.width - hKnobBounds.width) * getVisualScrollPercentX());
	if (scrollY)
		vKnobBounds.y = vScrollBounds.y + (int)((vScrollBounds.height - vKnobBounds.height) * (1 - getVisualScrollPercentY()));

	updateWidgetPosition();

	// Draw the background ninepatch.
	Color color = getColor();
	batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
	if (style.background != null) style.background.draw(batch, 0, 0, getWidth(), getHeight());

	// Caculate the scissor bounds based on the batch transform, the available widget area and the camera transform. We need to
	// project those to screen coordinates for OpenGL ES to consume.
	getStage().calculateScissors(widgetAreaBounds, scissorBounds);

	// Enable scissors for widget area and draw the widget.
	batch.flush();
	if (ScissorStack.pushScissors(scissorBounds)) {
		drawChildren(batch, parentAlpha);
		batch.flush();
		ScissorStack.popScissors();
	}

	// Render scrollbars and knobs on top if they will be visible
	float alpha = color.a * parentAlpha * Interpolation.fade.apply(fadeAlpha / fadeAlphaSeconds);
	drawScrollBars(batch, color.r, color.g, color.b, alpha);

	resetTransform(batch);
}
 
Example #27
Source File: CCParticleActor.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
protected void drawParticles(Batch batch) {
        int srcFunc = batch.getBlendSrcFunc();
        int dstFunc = batch.getBlendDstFunc();
        batch.setBlendFunction(blendSrc, blendDst);
        //System.out.println("_particleCount:"+_particleCount);
        for (int i = 0; i < _particleCount; i++) {
            batch.draw(m_pTexture, vertices[i], 0, 20);
        }
        batch.setBlendFunction(srcFunc, dstFunc);
//        batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }
 
Example #28
Source File: Box2dSteeringEntity.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
public void draw (Batch batch) {
	Vector2 pos = body.getPosition();
	float w = region.getRegionWidth();
	float h = region.getRegionHeight();
	float ox = w / 2f;
	float oy = h / 2f;

	batch.draw(region, //
		Box2dSteeringTest.metersToPixels(pos.x) - ox, Box2dSteeringTest.metersToPixels(pos.y) - oy, //
		ox, oy, //
		w, h, //
		1, 1, //
		body.getAngle() * MathUtils.radiansToDegrees); //
}
 
Example #29
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 #30
Source File: RenderedConsole.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void render(Batch b) {
  if (!visible || font == null) return;

  b.draw(modalBackground, 0, consoleY - 4, clientWidth, consoleHeight + 4);

  final int x = 2;
  String inputContents = in.getContents();
  GlyphLayout glyphs = font.draw(b, BUFFER_PREFIX + inputContents, x, bufferY - 2);
  b.draw(cursorTexture, x, bufferY, clientWidth, 2);
  if (showCaret) {
    final int caret = in.getCaretPosition();
    if (caret != in.length()) {
      glyphs.setText(font, BUFFER_PREFIX + inputContents.substring(0, caret));
    }

    b.draw(cursorTexture, x + glyphs.width, consoleY - 2, 2, textHeight);
  }
  Pools.free(glyphs);

  final float outputOffset = scrollOffset * lineHeight;
  if (outputOffset < outputHeight) {
    // offsets output to always appear that it starts at top of console window
    scrollOffset = Math.max(scrollOffset, scrollOffsetMin);
  }

  float position = outputY;
  final int outputSize = OUTPUT.size;
  if (scrollOffset > outputSize) {
    scrollOffset = outputSize;
    position += ((scrollOffsetMin - scrollOffset) * lineHeight);
  }

  for (int i = scrollOffset - 1; i >= 0; i--) {
    if (position > clientHeight) break;
    String line = OUTPUT.get(i);
    font.draw(b, line, x, position);
    position += lineHeight;
  }
}