Java Code Examples for com.badlogic.gdx.graphics.g2d.BitmapFont#setColor()

The following examples show how to use com.badlogic.gdx.graphics.g2d.BitmapFont#setColor() . 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: GameRenderer.java    From GdxDemo3D with Apache License 2.0 6 votes vote down vote up
public GameRenderer(Viewport viewport, Camera camera, GameEngine engine) {
	this.viewport = viewport;
	this.camera = camera;
	this.engine = engine;

	shapeRenderer = new MyShapeRenderer();
	shapeRenderer.setAutoShapeType(true);

	spriteBatch = new SpriteBatch();
	font = new BitmapFont();
	font.setColor(Color.WHITE);
	font.setUseIntegerPositions(false);
	font.getData().setScale(0.01f);
	shadowBatch = new ModelBatch(new DepthShaderProvider());

	ShaderProgram.pedantic = false;
	final String vertUber = Gdx.files.internal("shaders/uber.vert").readString();
	final String fragUber = Gdx.files.internal("shaders/uber.frag").readString();
	modelBatch = new ModelBatch(new DefaultShaderProvider(vertUber, fragUber) {
		@Override
		protected Shader createShader(final Renderable renderable) {
			return new UberShader(renderable, config);
		}
	});
}
 
Example 2
Source File: HighlightTextArea.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
@Override
protected void drawText (Batch batch, BitmapFont font, float x, float y) {
	maxAreaHeight = 0;
	float offsetY = 0;
	for (int i = firstLineShowing * 2; i < (firstLineShowing + linesShowing) * 2 && i < linesBreak.size; i += 2) {
		for (Chunk chunk : renderChunks) {
			if (chunk.lineIndex == i) {
				font.setColor(chunk.color);
				font.draw(batch, chunk.text, x + chunk.offsetX, y + offsetY);
			}
		}

		offsetY -= font.getLineHeight();
		maxAreaHeight += font.getLineHeight();
	}

	maxAreaHeight += 30;
}
 
Example 3
Source File: CocoStudioUIEditor.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
/**
 * 创建LabelStyle的BitmapFont
 *
 * @param option
 * @return
 */
public BitmapFont createLabelStyleBitmapFint(ObjectData option, String text,
                                             Color color) {

    FileHandle fontFile = null;
    if (ttfs != null && option.getFontResource() != null) {
        fontFile = ttfs.get(option.getFontResource().getPath());
    }

    if (fontFile == null) {// 使用默认字体文件
        fontFile = defaultFont;
    }

    if (fontFile == null) {
        try {
            debug(option, "ttf字体:" + option.getFontResource().getPath()
                + " 不存在,使用默认字体");
        } catch (Exception e) {
            //e.printStackTrace();
            debug(option, "不存在字体,使用默认字体");
        }
    }

    BitmapFont font = FontUtil.createFont(fontFile, text,
        option.getFontSize(), color);

    font.setColor(color);

    return font;
}
 
Example 4
Source File: ResourceManager.java    From TerraLegion with MIT License 5 votes vote down vote up
public BitmapFont getFont(String id, String file, Color color, int size) {
	FreeTypeFontGenerator gen = new FreeTypeFontGenerator(Gdx.files.internal(file));
	BitmapFont font = gen.generateFont(size);
	font.setColor(color);
	font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
	return font;
}
 
Example 5
Source File: MyButton.java    From killingspree with MIT License 5 votes vote down vote up
public void render(SpriteBatch batch, BitmapFont font, float delta){
    if (active) {
        font.setColor(1, 1, 1, 1);
        font.draw(batch, text, x + MathUtils.random(0, 1), y + MathUtils.random(0, 1));
    } else {
        font.setColor(0.5f, 0.5f, 0.5f, 1);
        font.draw(batch, text, x, y);
    }
    slackTime += delta;
}
 
Example 6
Source File: Box2dLightTest.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
@Override
public void create() {
	
	MathUtils.random.setSeed(Long.MIN_VALUE);

	camera = new OrthographicCamera(viewportWidth, viewportHeight);
	camera.position.set(0, viewportHeight / 2f, 0);
	camera.update();
	
	batch = new SpriteBatch();
	font = new BitmapFont();
	font.setColor(Color.RED);
	
	textureRegion = new TextureRegion(new Texture(
			Gdx.files.internal("data/marble.png")));
	bg = new Texture(Gdx.files.internal("data/bg.png"));

	createPhysicsWorld();
	Gdx.input.setInputProcessor(this);

	normalProjection.setToOrtho2D(
			0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

	/** BOX2D LIGHT STUFF BEGIN */
	RayHandler.setGammaCorrection(true);
	RayHandler.useDiffuseLight(true);
	
	rayHandler = new RayHandler(world);
	rayHandler.setAmbientLight(0f, 0f, 0f, 0.5f);
	rayHandler.setBlurNum(3);

	initPointLights();
	/** BOX2D LIGHT STUFF END */

}
 
Example 7
Source File: FilteredSelectBox.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
	validate();

	Drawable background;
	if (disabled && style.backgroundDisabled != null)
		background = style.backgroundDisabled;
	else if (selectBoxList.hasParent() && style.backgroundOpen != null)
		background = style.backgroundOpen;
	else if (clickListener.isOver() && style.backgroundOver != null)
		background = style.backgroundOver;
	else if (style.background != null)
		background = style.background;
	else
		background = null;
	BitmapFont font = style.font;
	Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor : style.fontColor;

	Color color = getColor();
	float x = getX(), y = getY();
	float width = getWidth(), height = getHeight();

	batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
	if (background != null)
		background.draw(batch, x, y, width, height);

	T selected = selection.first();
	if (selected != null) {
		if (background != null) {
			width -= background.getLeftWidth() + background.getRightWidth();
			height -= background.getBottomHeight() + background.getTopHeight();
			x += background.getLeftWidth();
			y += (int) (height / 2 + background.getBottomHeight() + font.getData().capHeight / 2);
		} else {
			y += (int) (height / 2 + font.getData().capHeight / 2);
		}
		font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
		drawItem(batch, font, selected, x, y, width);
	}
}
 
Example 8
Source File: ResourceManager.java    From TerraLegion with MIT License 4 votes vote down vote up
public BitmapFont getFont(String id, String fileFNT, String filePNG, Color color, float scale) {
	BitmapFont font = new BitmapFont(Gdx.files.internal(fileFNT),Gdx.files.internal(filePNG),false);
	font.setColor(color);
	font.setScale(scale);
	return font;
}
 
Example 9
Source File: VisTextField.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	Stage stage = getStage();
	boolean focused = stage != null && stage.getKeyboardFocus() == this;
	if (!focused) keyRepeatTask.cancel();

	final BitmapFont font = style.font;
	final Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor
			: ((focused && style.focusedFontColor != null) ? style.focusedFontColor : style.fontColor);
	final Drawable selection = style.selection;
	final Drawable cursorPatch = style.cursor;
	Drawable background = (disabled && style.disabledBackground != null) ? style.disabledBackground
			: ((focused && style.focusedBackground != null) ? style.focusedBackground : style.background);

	// vis
	if (!disabled && style.backgroundOver != null && (clickListener.isOver() || focused)) {
		background = style.backgroundOver;
	}

	Color color = getColor();
	float x = getX();
	float y = getY();
	float width = getWidth();
	float height = getHeight();

	batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
	float bgLeftWidth = 0, bgRightWidth = 0;
	if (background != null) {
		background.draw(batch, x, y, width, height);
		bgLeftWidth = background.getLeftWidth();
		bgRightWidth = background.getRightWidth();
	}

	float textY = getTextY(font, background);
	calculateOffsets();

	if (focused && hasSelection && selection != null) {
		drawSelection(selection, batch, font, x + bgLeftWidth, y + textY);
	}

	float yOffset = font.isFlipped() ? -textHeight : 0;
	if (displayText.length() == 0) {
		if (!focused && messageText != null) {
			if (style.messageFontColor != null) {
				font.setColor(style.messageFontColor.r, style.messageFontColor.g, style.messageFontColor.b,
						style.messageFontColor.a * color.a * parentAlpha);
			} else
				font.setColor(0.7f, 0.7f, 0.7f, color.a * parentAlpha);
			BitmapFont messageFont = style.messageFont != null ? style.messageFont : font;
			messageFont.draw(batch, messageText, x + bgLeftWidth, y + textY + yOffset, 0, messageText.length(),
					width - bgLeftWidth - bgRightWidth, textHAlign, false, "...");
		}
	} else {
		font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * color.a * parentAlpha);
		drawText(batch, font, x + bgLeftWidth, y + textY + yOffset);
	}
	if (drawBorder && focused && !disabled) {
		blink();
		if (cursorOn && cursorPatch != null) {
			drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY);
		}
	}

	// vis
	if (isDisabled() == false && inputValid == false && style.errorBorder != null)
		style.errorBorder.draw(batch, getX(), getY(), getWidth(), getHeight());
	else if (focusBorderEnabled && drawBorder && style.focusBorder != null)
		style.focusBorder.draw(batch, getX(), getY(), getWidth(), getHeight());

}
 
Example 10
Source File: Box2dLightCustomShaderTest.java    From box2dlights with Apache License 2.0 4 votes vote down vote up
@Override
public void create() {
	bg = new Texture(Gdx.files.internal("data/bg-deferred.png"));
	bgN = new Texture(Gdx.files.internal("data/bg-deferred-n.png"));

	MathUtils.random.setSeed(Long.MIN_VALUE);

	camera = new OrthographicCamera(viewportWidth, viewportHeight);
	camera.update();

	viewport = new FitViewport(viewportWidth, viewportHeight, camera);

	batch = new SpriteBatch();
	font = new BitmapFont();
	font.setColor(Color.RED);

	TextureRegion marbleD = new TextureRegion(new Texture(
		Gdx.files.internal("data/marble.png")));

	TextureRegion marbleN = new TextureRegion(new Texture(
		Gdx.files.internal("data/marble-n.png")));

	marble = new DeferredObject(marbleD, marbleN);
	marble.width = RADIUS * 2;
	marble.height = RADIUS * 2;

	createPhysicsWorld();
	Gdx.input.setInputProcessor(this);

	normalProjection.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

	/** BOX2D LIGHT STUFF BEGIN */
	RayHandler.setGammaCorrection(true);
	RayHandler.useDiffuseLight(true);

	normalShader = createNormalShader();

	lightShader = createLightShader();
	rayHandler = new RayHandler(world, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()) {
		@Override protected void updateLightShader () {}

		@Override protected void updateLightShaderPerLight (Light light) {
			// light position must be normalized
			float x = (light.getX())/viewportWidth;
			float y = (light.getY())/viewportHeight;
			lightShader.setUniformf("u_lightpos", x, y, 0.05f);
			lightShader.setUniformf("u_intensity", 5);
		}
	};
	rayHandler.setLightShader(lightShader);
	rayHandler.setAmbientLight(0.1f, 0.1f, 0.1f, 0.5f);
	rayHandler.setBlurNum(0);

	initPointLights();
	/** BOX2D LIGHT STUFF END */


	objectReg = new TextureRegion(new Texture(Gdx.files.internal("data/object-deferred.png")));
	objectRegN = new TextureRegion(new Texture(Gdx.files.internal("data/object-deferred-n.png")));

	for (int x = 0; x < 4; x++) {
		for (int y = 0; y < 3; y++) {
			DeferredObject deferredObject = new DeferredObject(objectReg, objectRegN);
			deferredObject.x = 4 + x * (deferredObject.diffuse.getRegionWidth()*SCALE + 8);
			deferredObject.y = 4 + y * (deferredObject.diffuse.getRegionHeight()*SCALE + 7);
			deferredObject.color.set(MathUtils.random(0.5f, 1), MathUtils.random(0.5f, 1), MathUtils.random(0.5f, 1), 1);
			if (x > 0)
				deferredObject.rot = true;
			deferredObject.rotation = MathUtils.random(90);
			assetArray.add(deferredObject);
		}
	}
	once = false;
	normalFbo = new FrameBuffer(Pixmap.Format.RGB565, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
}