List of usage examples for com.badlogic.gdx.graphics.g2d SpriteBatch draw
@Override
public void draw(TextureRegion region, float x, float y, float width, float height)
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 ww w .ja 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.GameScreen.java
License:Apache License
@Override public void render(SpriteBatch spriteBatch) { if (model == null) { startGame();// www. j av 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.buttonPressTimeout = 1f; assets.options.gameState = GameOptions.STATE_MENU; } h = MemoryGame.HEIGHT; cardHeight = (h - (numRows + 1) * offset) / numRows; // determine which card has been clicked and react in the model ... // but only if the intro animation is over ... if (model.introAnimation < 0) { compute(offset, cardHeight); // one time covering action after the animation. if (model.needsToBeCovered) { model.coverCards(); model.needsToBeCovered = false; } } else model.introAnimation -= Gdx.graphics.getDeltaTime(); // game time; if (!model.finished) model.time += Gdx.graphics.getDeltaTime(); // the drawing spriteBatch.begin(); // draw background ... spriteBatch.draw(assets.background, 0, 0, MemoryGame.WIDTH, MemoryGame.HEIGHT); for (int r = 0; r < numRows; r++) { for (int c = 0; c < numCols; c++) { cardX = c * (cardHeight - cardHeight / 5.5f); cardY = offset + r * (cardHeight + offset); float cardTime = model.introAnimationLength / ((float) model.numCards); if (cardTime * (c + numCols * r) < model.introAnimationLength - model.introAnimation) { // if is for the start animation ... also compensates the first click :) // draw the card ... if (model.getState((c + numCols * r)) == 0) { spriteBatch.draw(assets.cardBackMark, cardX, cardY, cardHeight, cardHeight); } else if (model.getState((c + numCols * r)) == 1) { spriteBatch.draw(assets.cardBack, cardX, cardY, cardHeight, cardHeight); } else if (model.getState((c + numCols * r)) >= 2) { spriteBatch.draw(assets.card, cardX, cardY, cardHeight, cardHeight); if (assets.icons == null) { String str = "" + model.icon[(c + numCols * r)]; assets.font.draw(spriteBatch, str, cardX + cardHeight / 2 - assets.font.getBounds(str).width / 2, cardY + cardHeight / 2 + assets.font.getBounds(str).height / 2); } else { float iconSize = cardHeight / 2; spriteBatch.draw(assets.icons[model.icon[(c + numCols * r)]], cardX + cardHeight / 2 - iconSize / 2, cardY + cardHeight / 2 - iconSize / 2, iconSize, iconSize); } if (model.getState((c + numCols * r)) == 3 && !model.finished) { spriteBatch.draw(assets.check, cardX + cardHeight - 2f * cardHeight / 5.5f, cardY + cardHeight / 16f, 32, 32); } } // draw the icon ... } } } // draw time and moves ... if (model.introAnimation < 0 & !model.finished) { String moves = model.numberOfMoves + " tries"; int secs = ((int) Math.floor(model.time)) % 60; int min = ((int) Math.floor(model.time)) / 60; String timeString = min + ":" + (secs < 10 ? "0" : "") + secs; assets.font.draw(spriteBatch, moves, MemoryGame.WIDTH - assets.font.getBounds(moves).width - 10, offset + assets.font.getLineHeight()); assets.font.draw(spriteBatch, timeString, MemoryGame.WIDTH - assets.font.getBounds(timeString).width - 10, offset + assets.font.getLineHeight() * 2); } // spriteBatch.draw(assets.undo, MemoryGame.WIDTH - assets.undo.getWidth() - 10, MemoryGame.HEIGHT - assets.undo.getHeight() - 10); if (model.finished) { spriteBatch.draw(assets.grey, 0, 0, MemoryGame.WIDTH, MemoryGame.HEIGHT); spriteBatch.draw(assets.positive, MemoryGame.WIDTH / 2 - assets.positive.getWidth() / 2, MemoryGame.HEIGHT / 2 - assets.positive.getHeight() / 2); assets.font.draw(spriteBatch, "Congratulations!", MemoryGame.WIDTH / 2 - assets.font.getBounds("Congratulations!").width / 2, MemoryGame.HEIGHT - assets.font.getBounds("Congratulations!").height); int secs = ((int) Math.floor(model.time)) % 60; int min = ((int) Math.floor(model.time)) / 60; String timeString = "Solved in " + min + ":" + (secs < 10 ? "0" : "") + secs + " and " + model.numberOfMoves + " tries"; assets.smallFont.draw(spriteBatch, timeString, MemoryGame.WIDTH / 2 - assets.smallFont.getBounds(timeString).width / 2, assets.smallFont.getBounds(timeString).height * 2); assets.fireworks.findEmitter("fireworks").setPosition(MemoryGame.WIDTH - 100, 0); assets.fireworks.findEmitter("fireworks").draw(spriteBatch, Gdx.graphics.getDeltaTime()); } 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;//from ww w .j a v a 2 s .c o m 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:at.tugraz.ist.catroid.plugin.Drone.other.DroneVideoCostume.java
License:Open Source License
@Override public void draw(SpriteBatch batch, float parentAlpha) { if (firstStart) { initializeTexture();//from w ww . ja va2 s . com } else { DroneHandler.getInstance().getDrone() .renderVideoFrame(this.region.getTexture().getTextureObjectHandle()); int newCameraOrientation = DroneHandler.getInstance().getDrone().getCameraOrientation(); if (oldCameraOrientation != newCameraOrientation) { oldCameraOrientation = newCameraOrientation; if (newCameraOrientation == 1) { this.region.setRegion(0, 0, 176, 144); } else { this.region.setRegion(0, 0, 320, 240); } } if (region.getTexture() != null) { batch.setColor(color.r, color.g, color.b, color.a * this.alphaValue); if (scaleX == 1 && scaleY == 1 && rotation == 0) { batch.draw(region, x, y, width, height); } else { batch.draw(region, x, y, originX, originY, width, height, scaleX, scaleY, rotation); } } } }
From source file:br.ufms.mechsmasher.scenes.Tutorial.java
@Override public void draw(SpriteBatch batch) { final float x = 0.0f; final float y = 0.0f; final float width = getSceneManager().getCamera().viewportWidth; final float height = getSceneManager().getCamera().viewportHeight; batch.draw(background, x, y, width, height); batch.draw(text, x, y, width, height); }
From source file:com.badlydrawngames.general.SimpleButton.java
License:Apache License
public void draw(SpriteBatch spriteBatch) { Color oldColor = font.getColor(); if (down) {/* w w w .j a va2 s .c om*/ 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.belocraft.ui.SimpleButton.java
public void draw(SpriteBatch batcher) { if (isPressed) { batcher.draw(buttonDown, x, y, width, height); } else {/*w w w .j a v a 2 s . co m*/ batcher.draw(buttonUp, x, y, width, height); } }
From source file:com.bladecoder.engine.model.ImageRenderer.java
License:Apache License
@Override public void draw(SpriteBatch batch, float x, float y, float scale) { x = x - getWidth() / 2 * scale; // SET THE X ORIGIN TO THE CENTER OF THE // SPRITE//www . j av a2 s. c o m if (currentSource == null || currentSource.tex == null) { RectangleRenderer.draw(batch, x, y, getWidth() * scale, getHeight() * scale, Color.RED); return; } if (!flipX) { batch.draw(currentSource.tex, x, y, currentSource.tex.getWidth() * scale, currentSource.tex.getHeight() * scale); } else { batch.draw(currentSource.tex, x, y, -currentSource.tex.getWidth() * scale, currentSource.tex.getHeight() * scale); } }
From source file:com.bladecoder.engine.ui.HelpScreen.java
License:Apache License
@Override public void render(float delta) { SpriteBatch batch = ui.getBatch(); Gdx.gl.glClearColor(0, 0, 0, 1);/* w w w . j av a2s . co m*/ Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setProjectionMatrix(viewport.getCamera().combined); batch.begin(); batch.draw(tex, 0, 0, viewport.getScreenWidth(), viewport.getScreenHeight()); batch.end(); }
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);//w w w . j av a 2 s . co m 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(); }