List of usage examples for com.badlogic.gdx.graphics.g2d SpriteBatch setColor
@Override
public void setColor(float color)
From source file:at.juggle.games.memory.CreditsScreen.java
License:Apache License
@Override public void render(SpriteBatch spriteBatch) { float h = MemoryGame.HEIGHT; float l = font.getLineHeight(); minTimeShown -= Gdx.graphics.getDeltaTime(); if (Gdx.input.justTouched() & minTimeShown < 0) { assets.options.gameState = GameOptions.STATE_MENU; minTimeShown = 2f;//from w w w.j a v a2 s. c o m } // key listener ... if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE) || Gdx.input.isKeyPressed(Input.Keys.BACK)) { // get back to menu ... assets.options.gameState = GameOptions.STATE_MENU; } offset += Gdx.graphics.getDeltaTime() * 35f; if (offset > MemoryGame.HEIGHT) offset = -(creditsLines.length) * font.getLineHeight(); spriteBatch.begin(); // draw background ... spriteBatch.draw(assets.background, 0, 0, MemoryGame.WIDTH, MemoryGame.HEIGHT); spriteBatch.setColor(Color.WHITE); for (int i = 0; i < creditsLines.length; i++) { String line = creditsLines[i]; font.draw(spriteBatch, line, 16, offset + (creditsLines.length - i) * font.getLineHeight()); } // draw gradients for the fx spriteBatch.draw(assets.gradientBottom, 0, 0, MemoryGame.WIDTH, assets.gradientBottom.getHeight()); spriteBatch.draw(assets.gradientTop, 0, MemoryGame.HEIGHT - assets.gradientTop.getHeight(), MemoryGame.WIDTH, assets.gradientTop.getHeight()); spriteBatch.end(); }
From source file:at.juggle.games.memory.MenuScreen.java
License:Apache License
@Override public void render(SpriteBatch spriteBatch) { assets.font.setScale(scaleFont, scaleFont); assets.font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); h = MemoryGame.HEIGHT;/*www . j a va 2 s. com*/ l = assets.font.getLineHeight() * scaleFont + 18; if (Gdx.input.justTouched()) { // (x,y) from top left corner float x = Gdx.input.getX() / ((float) Gdx.graphics.getWidth()) * ((float) MemoryGame.WIDTH); float y = Gdx.input.getY() / ((float) Gdx.graphics.getHeight()) * ((float) MemoryGame.HEIGHT); if (x > l && x < 2 * MemoryGame.WIDTH / 3) { if (y > l + 5 && y < 2 * l - 10) { // new Game assets.options.gameState = GameOptions.STATE_GAME; } else if (y > 2 * l + 5 && y < 3 * l - 10) { // number of cards changed assets.options.nextNumberOfCards(); } else if (y > 3 * l + 5 && y < 4 * l - 10) { // Mode assets.options.toggleGameMode(); } else if (y > 4 * l + 5 && y < 5 * l - 10) { // Sound assets.options.toggleSoundOn(); } else if (y > 5 * l + 5 && y < 6 * l - 10) { // credits assets.options.gameState = GameOptions.STATE_CREDITS; } } } // key listener ... if (assets.options.buttonPressTimeout < 0) { if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE) || Gdx.input.isKeyPressed(Input.Keys.BACK)) { // use the back button Gdx.app.exit(); } } else assets.options.buttonPressTimeout -= Gdx.graphics.getDeltaTime(); // do the drawing ... spriteBatch.begin(); // draw background ... spriteBatch.draw(assets.background, 0, 0, MemoryGame.WIDTH, MemoryGame.HEIGHT); spriteBatch.setColor(Color.WHITE); if (MemoryGame.WIDTH / 3 - 20 < assets.logo.getWidth()) { // draw logo scaled float logoWidth = (int) (MemoryGame.WIDTH / 3f - 20f); spriteBatch.draw(assets.logo, MemoryGame.WIDTH - logoWidth - 10, 0, logoWidth, logoWidth); } else { spriteBatch.draw(assets.logo, MemoryGame.WIDTH - assets.logo.getWidth() - 10, 0); } assets.font.draw(spriteBatch, "> New Game", l, h - l); assets.font.draw(spriteBatch, "> Cards: ", l, h - 2 * l); assets.font.draw(spriteBatch, assets.options.getNumberOfCards() + "", 2 * MemoryGame.WIDTH / 3 - assets.font.getBounds(assets.options.getNumberOfCards() + "").width, h - 2 * l); assets.font.draw(spriteBatch, "> Mode: ", l, h - 3 * l); assets.font.draw(spriteBatch, assets.options.getGameModeString(), 2 * MemoryGame.WIDTH / 3 - assets.font.getBounds(assets.options.getGameModeString()).width, h - 3 * l); assets.font.draw(spriteBatch, "> Sound: ", l, h - 4 * l); assets.font.draw(spriteBatch, (assets.options.soundOn) ? "On" : "Off", 2 * MemoryGame.WIDTH / 3 - assets.font.getBounds((assets.options.soundOn) ? "On" : "Off").width, h - 4 * l); assets.font.draw(spriteBatch, "> Credits", l, h - 5 * l); spriteBatch.end(); }
From source file:com.badlydrawngames.general.SimpleButton.java
License:Apache License
public void draw(SpriteBatch spriteBatch) { Color oldColor = font.getColor(); if (down) {//from ww w . ja va2 s .co m spriteBatch.setColor(Color.RED); } else { spriteBatch.setColor(Color.BLUE); } spriteBatch.draw(Assets.pureWhiteTextureRegion, x, y, w, h); spriteBatch.setColor(Color.WHITE); if (down) { font.setColor(oldColor.r / 2, oldColor.g / 2, oldColor.b / 2, oldColor.a); } float textX = x; float textY = y + h; textY -= (h - textHeight) / 2; font.drawWrapped(spriteBatch, text, textX, textY, w, alignment); font.setColor(oldColor); }
From source file:com.bladecoder.engine.ui.defaults.ScenePointer.java
License:Apache License
public void draw(SpriteBatch batch, Viewport v) { getInputUnproject(v, mousepos);/*w w w. j a v a2 s. c o m*/ boolean multiTouch = Gdx.input.isPeripheralAvailable(Peripheral.MultitouchScreen); // DRAW TARGET DESCRIPTION if (desc != null && (!multiTouch || Gdx.input.isTouched())) { float margin = DPIUtils.UI_SPACE; float textX = mousepos.x - layout.width / 2; float textY = mousepos.y + layout.height + DPIUtils.UI_SPACE + DPIUtils.getTouchMinSize(); if (textX < 0) textX = 0; RectangleRenderer.draw(batch, textX - margin, textY - layout.height - margin, layout.width + margin * 2, layout.height + margin * 2, Color.BLACK); font.draw(batch, layout, textX, textY); } if (draggingRenderer == null) { if (!multiTouch || currentIcon == leaveIcon) { batch.draw(currentIcon, mousepos.x - currentIcon.getRegionWidth() / 2, mousepos.y - currentIcon.getRegionHeight() / 2, currentIcon.getRegionWidth() / 2, currentIcon.getRegionHeight() / 2, currentIcon.getRegionWidth(), currentIcon.getRegionHeight(), pointerScale, pointerScale, currentIcon == leaveIcon ? leaveRotation : 0); } } else { float h = (draggingRenderer.getHeight() > draggingRenderer.getWidth() ? draggingRenderer.getHeight() : draggingRenderer.getWidth()); float size = DPIUtils.getTouchMinSize() / h * 1.8f; if (currentIcon != hotspotIcon) { batch.setColor(DRAG_NOT_HOTSPOT_COLOR); } draggingRenderer.draw(batch, mousepos.x, mousepos.y - draggingRenderer.getHeight() * size / 2, size); if (currentIcon != hotspotIcon) { batch.setColor(Color.WHITE); } } }
From source file:com.bladecoder.engine.ui.InitScreen.java
License:Apache License
@Override public void render(float delta) { SpriteBatch batch = ui.getBatch(); Gdx.gl.glClearColor(0, 0, 0, 1);/*from ww w .j a v a 2 s. com*/ Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setProjectionMatrix(viewport.getCamera().combined); batch.begin(); if (time > FADE_TIME * 2 + SCREEN_TIME) { // EXIT INIT SCREEN batch.setColor(Color.WHITE); ui.setCurrentScreen(Screens.MENU_SCREEN); } else if (time > FADE_TIME + SCREEN_TIME) { // FADE_OUT batch.setColor(1, 1, 1, 1 - fadeTime / FADE_TIME); } else if (time < FADE_TIME) { // FADE IN batch.setColor(1, 1, 1, fadeTime / FADE_TIME); } else { fadeTime = 0; } final int viewportW = viewport.getScreenWidth(); final int viewportH = viewport.getScreenHeight(); final float texW = tex.getWidth() * scale; final float texH = tex.getHeight() * scale; batch.draw(tex, (viewportW - texW) / 2, (viewportH - texH) / 2, texW, texH); batch.setColor(1, 1, 1, 1); time += delta; fadeTime += delta; batch.end(); }
From source file:com.bladecoder.engineeditor.ui.SceneList.java
License:Apache License
private TextureRegion createBgIcon(String atlas, String region) { TextureAtlas a = new TextureAtlas(Gdx.files .absolute(Ctx.project.getProjectPath() + "/" + Project.ATLASES_PATH + "/1/" + atlas + ".atlas")); AtlasRegion r = a.findRegion(region); if (r == null) { a.dispose();/*from ww w. j a v a2s .c om*/ return null; } FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, 200, (int) (r.getRegionHeight() * 200f / r.getRegionWidth()), false); SpriteBatch fboBatch = new SpriteBatch(); fboBatch.setColor(Color.WHITE); OrthographicCamera camera = new OrthographicCamera(); camera.setToOrtho(false, fbo.getWidth(), fbo.getHeight()); fboBatch.setProjectionMatrix(camera.combined); Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST); fbo.begin(); fboBatch.begin(); fboBatch.draw(r, 0, 0, fbo.getWidth(), fbo.getHeight()); fboBatch.end(); TextureRegion tex = ScreenUtils.getFrameBufferTexture(0, 0, fbo.getWidth(), fbo.getHeight()); // tex.flip(false, true); fbo.end(); Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST); fbo.dispose(); a.dispose(); fboBatch.dispose(); return tex; }
From source file:com.packtpub.libgdx.canyonbunny.game.objects.BunnyHead.java
License:Apache License
@Override public void render(SpriteBatch batch) { TextureRegion reg = null;/*from ww w. j av a 2s. c o m*/ // Draw Particles dustParticles.draw(batch); // Apply Skin Color batch.setColor(CharacterSkin.values()[GamePreferences.instance.charSkin].getColor()); // Set special color when game object has a feather power-up if (hasFeatherPowerup) { batch.setColor(1.0f, 0.8f, 0.0f, 1.0f); } // Draw image reg = regHead; batch.draw(reg.getTexture(), position.x, position.y, origin.x, origin.y, dimension.x, dimension.y, scale.x, scale.y, rotation, reg.getRegionX(), reg.getRegionY(), reg.getRegionWidth(), reg.getRegionHeight(), viewDirection == VIEW_DIRECTION.LEFT, false); // Reset color to white batch.setColor(1, 1, 1, 1); }
From source file:com.ridiculousRPG.animation.WeatherEffectLayer.java
License:Apache License
/** * Draw the effect-layer.//from w ww . j a va2 s . c o m */ public void draw(SpriteBatch batch, Camera cam, boolean debug) { if (flip) { batch.setTransformMatrix(compTransMatrix(batch, cam)); } if (fadeAlpha < 1f) { Color c = batch.getColor(); c.a *= fadeAlpha; batch.setColor(c); fadeAlpha += fadeBy * Gdx.graphics.getDeltaTime(); if (fadeAlpha > 1f) fadeAlpha = 1f; } // load frequently used variables into registers Texture t = tRef.getTexture(); int tWidth = tRef.getRegionWidth(); int tHeight = tRef.getRegionHeight(); float x1 = Math.max(0f, cam.position.x); float y1 = Math.max(0f, cam.position.y); float x2 = Math.min(width, x1 + cam.viewportWidth); float y2 = Math.min(height, y1 + cam.viewportHeight); float x3 = x1 - tWidth; float y3 = y1 - tHeight; float x4 = x2 - tWidth; float y4 = y2 - tHeight; for (List<Rectangle> row : tileLayer) { for (Rectangle clip : row) { float x = clip.x; float y = clip.y; if (x > x3 && y > y3 && x < x2 && y < y2) { // texel space origin is upper left corner (unlike screen // space) int srcX = 0; int srcY = 0; int srcWidth = tWidth; int srcHeight = tHeight; if (x < x1) { srcX = (int) (x1 - x + .7f); srcWidth -= srcX; x += srcX; } if (x > x4) { srcWidth -= x - x4; } if (y < y1) { srcHeight -= y1 - y; y = y1; } if (y > y4) { srcY = (int) (y - y4); srcHeight -= srcY; y += y - y4 - srcY; } batch.draw(t, x, y, srcX, srcY, srcWidth, srcHeight); } } } if (flip) { batch.setTransformMatrix(batch.getTransformMatrix().idt()); } /* * if (debug) { batch.end(); List<Rectangle> rects = new * ArrayList<Rectangle>(); for (List<Rectangle> row : tileLayer) for * (Rectangle clip : row) rects.add(new Rectangle(clip.x, clip.y, * Math.abs(tWidth), Math.abs(tHeight))); DebugHelper.debugRectangle(new * Color(1f, 0.67f, 0f, .4f), flip ? compTransMatrix(batch, cam) : null, * rects .toArray(new Rectangle[0])); batch.begin(); } */ }
From source file:com.ridiculousRPG.event.EventObject.java
License:Apache License
public void draw(SpriteBatch spriteBatch) { if (visible) { drawDoneSwitch = true;/*from w w w . j a va2 s . c o m*/ float eventColorBits = this.colorFloatBits; float gameColorBits = GameBase.$().getGameColorBits(); if (gameColorBits != COLOR_WHITE_BITS) { if (eventColorBits != COLOR_WHITE_BITS) { Color c1 = this.color; Color c2 = GameBase.$().getGameColorTint(); eventColorBits = Color.toFloatBits(c1.r * c2.r, c1.g * c2.g, c1.b * c2.b, c1.a * c2.a); } else { eventColorBits = gameColorBits; } } float x = drawBound.x; float y = drawBound.y; float h = drawBound.height; float w = drawBound.width; float oX = getOffsetX(); float oY = getOffsetY(); spriteBatch.setColor(eventColorBits); boolean trans = oX != 0 || oY != 0; if (trans) spriteBatch.setTransformMatrix(spriteBatch.getTransformMatrix().translate(oX, oY, 0)); if (effectRear != null) effectRear.draw(spriteBatch); if (image != null) spriteBatch.draw(image, x, y, w * .5f, h * .5f, w, h, scaleX, scaleY, rotation); if (effectFront != null) effectFront.draw(spriteBatch); if (trans) spriteBatch.setTransformMatrix(spriteBatch.getTransformMatrix().translate(-oX, -oY, 0)); spriteBatch.setColor(gameColorBits); } }
From source file:com.ridiculousRPG.GameServiceProvider.java
License:Apache License
private Matrix4 drawWithMatrix(boolean debug, SpriteBatch spriteBatch, Camera camera, Matrix4 old, Drawable d, float tintColorBits) { if (d.projectionMatrix(camera) != old) { if (old != null) { spriteBatch.end();/*www . j a v a2 s . c om*/ } old = d.projectionMatrix(camera); spriteBatch.setProjectionMatrix(old); spriteBatch.begin(); } spriteBatch.setColor(tintColorBits); d.draw(spriteBatch, camera, debug); return old; }