List of usage examples for com.badlogic.gdx.graphics.g2d Sprite setPosition
public void setPosition(float x, float y)
From source file:at.therefactory.jewelthief.screens.MenuScreen.java
License:Open Source License
private void initStars() { spritesStars = new Sprite[MENU_SCREEN_NUM_STARS]; starSpeeds = new float[MENU_SCREEN_NUM_STARS]; for (int i = 0; i < MENU_SCREEN_NUM_STARS; i++) { Sprite star = JewelThief.getInstance().getTextureAtlas().createSprite("star"); star.setPosition( Utils.randomWithin(borderSize + star.getWidth(), WINDOW_WIDTH - borderSize - star.getWidth()), Utils.randomWithin(borderSize, WINDOW_HEIGHT - star.getHeight())); spritesStars[i] = star;// www. j a v a2s.co m starSpeeds[i] = Utils.randomWithin(.01f, .2f); } }
From source file:at.therefactory.jewelthief.screens.MenuScreen.java
License:Open Source License
public void handleTouchOnStars(Vector3 touchCoordinates) { if (touchCoordinates.y > spriteSkyline.getY()) { for (Sprite star : spritesStars) { if (Utils.within(touchCoordinates.x, star.getX(), star.getX() + star.getWidth()) && Utils.within(touchCoordinates.y, star.getY(), star.getY() + star.getHeight())) { JewelThief.getInstance().playCymbalSound(); star.setPosition(star.getX(), WINDOW_HEIGHT + star.getHeight() * 3); }/*ww w .jav a 2 s.c om*/ } } }
From source file:aurelienribon.texturepackergui.Canvas.java
License:Apache License
@Override public void render() { if (previousPageRequested) { previousPageRequested = false;/*w ww . j a v a2 s. c o m*/ index = index - 1 < 0 ? sprites.size() - 1 : index - 1; } if (nextPageRequested) { nextPageRequested = false; index = index + 1 >= sprites.size() ? 0 : index + 1; } if (packReloadRequested) { packReloadRequested = false; index = 0; camera.position.set(0, 0, 0); camera.update(); sprites.clear(); if (atlas != null) atlas.dispose(); if (packFile != null && packFile.exists()) { try { atlas = new TextureAtlas(packFile); List<Texture> textures = new ArrayList<Texture>(); for (AtlasRegion region : atlas.getRegions()) { if (!textures.contains(region.getTexture())) textures.add(region.getTexture()); } for (Texture tex : textures) { Sprite sp = new Sprite(tex); sp.setOrigin(sp.getWidth() / 2, sp.getHeight() / 2); sp.setPosition(-sp.getOriginX(), -sp.getOriginY()); sprites.add(sp); } } catch (GdxRuntimeException ex) { atlas = null; sprites.clear(); callback.atlasError(); } } } // Render Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); float tw = bgTex.getWidth(); float th = bgTex.getHeight(); batch.getProjectionMatrix().setToOrtho2D(0, 0, w, h); batch.begin(); batch.disableBlending(); batch.draw(bgTex, 0f, 0f, w, h, 0f, 0f, w / tw, h / th); batch.enableBlending(); batch.end(); batch.setProjectionMatrix(camera.combined); batch.begin(); if (!sprites.isEmpty()) sprites.get(index).draw(batch); batch.end(); batch.getProjectionMatrix().setToOrtho2D(0, 0, w, h); batch.begin(); font.setColor(Color.WHITE); lblNextPage.draw(batch); lblPreviousPage.draw(batch); infoLabel.draw(batch); if (sprites.isEmpty()) font.draw(batch, "No page to show", 10, 65); else font.draw(batch, "Page " + (index + 1) + " / " + sprites.size(), 10, 65); font.draw(batch, String.format(Locale.US, "Zoom: %.0f %%", 100f / camera.zoom), 10, 45); font.draw(batch, "Fps: " + Gdx.graphics.getFramesPerSecond(), 10, 25); batch.end(); }
From source file:br.cefetmg.games.minigames.CollectItens.java
private void spawnLollipop() { // pega x e y entre 0 e 1 Vector2 position = new Vector2(rand.nextFloat(), rand.nextFloat()); if (quantAtualLollipops < totalLollipops) { // multiplica x e y pela largura e altura da tela position.scl(//from ww w . j a va 2 s .c o m this.screen.viewport.getScreenWidth() - lollipopTexture.getWidth() * initialCharactersScale, this.screen.viewport.getScreenHeight() - lollipopTexture.getHeight() * initialCharactersScale); Sprite lollipop = new Sprite(lollipopTexture); lollipop.setPosition(position.x, position.y); lollipop.setScale(initialCharactersScale); this.characters.add(lollipop); this.enemiesAppearing.play(); } }
From source file:br.cefetmg.games.minigames.CollectItens.java
private void spawnCandy() { // pega x e y entre 0 e 1 Vector2 position = new Vector2(rand.nextFloat(), rand.nextFloat()); if (quantAtualCandies < totalCandies) { // multiplica x e y pela largura e altura da tela position.scl(this.screen.viewport.getScreenWidth() - candyTexture.getWidth() * initialCharactersScale, this.screen.viewport.getScreenHeight() - candyTexture.getHeight() * initialCharactersScale); Sprite candy = new Sprite(candyTexture); candy.setPosition(position.x, position.y); candy.setScale(initialCharactersScale); this.characters.add(candy); friends++;/* w ww . ja va 2 s . c o m*/ // toca um efeito sonoro this.enemiesAppearing.play(); } }
From source file:br.cefetmg.games.minigames.CollectItens.java
private void spawnToothpaste() { // pega x e y entre 0 e 1 Vector2 position = new Vector2(rand.nextFloat(), rand.nextFloat()); if (quantAtualToothpaste < totalToothpaste) { // multiplica x e y pela largura e altura da tela position.scl(//from www .j a va2 s.c o m this.screen.viewport.getScreenWidth() - toothpasteTexture.getWidth() * initialCharactersScale, this.screen.viewport.getScreenHeight() - toothpasteTexture.getHeight() * initialCharactersScale); Sprite toothpaste = new Sprite(toothpasteTexture); toothpaste.setPosition(position.x, position.y); toothpaste.setScale(initialCharactersScale); this.characters.add(toothpaste); // toca um efeito sonoro this.friendsAppearing.play(); friends++; } }
From source file:br.cefetmg.games.minigames.CollectItens.java
private void spawnToothbrush() { // pega x e y entre 0 e 1 Vector2 position = new Vector2(rand.nextFloat(), rand.nextFloat()); if (quantAtualToothbrush < totalToothbrush) { // multiplica x e y pela largura e altura da tela position.scl(/*from w w w .j a v a2 s. c o m*/ this.screen.viewport.getScreenWidth() - toothbrushTexture.getWidth() * initialCharactersScale, this.screen.viewport.getScreenHeight() - toothbrushTexture.getHeight() * initialCharactersScale); Sprite toothbrush = new Sprite(toothbrushTexture); toothbrush.setPosition(position.x, position.y); toothbrush.setScale(initialCharactersScale); this.characters.add(toothbrush); } // toca um efeito sonoro this.friendsAppearing.play(); }
From source file:br.cefetmg.games.minigames.EscoveOsDentes.java
private void spawnEnemy() { // pega x e y entre 0 e 1 Vector2 position = new Vector2(rand.nextFloat(), rand.nextFloat()); // multiplica x e y pela largura e altura da tela position.scl(this.screen.viewport.getWorldWidth() - toothTexture.getWidth() * initialToothScale, this.screen.viewport.getWorldHeight() - toothTexture.getHeight() * initialToothScale); Sprite enemy = new Sprite(toothTexture); Escova novo = new Escova(); enemy.setPosition(position.x, position.y); enemy.setScale(minimumToothScale);// w w w . jav a 2s . com Tooths.add(enemy); Escovar.add(novo); }
From source file:br.cefetmg.games.minigames.Gallows.java
@Override public void onHandlePlayingInput() { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. // atualiza a posio do alvo de acordo com o mouse Vector2 click = new Vector2(Gdx.input.getX(), Gdx.input.getY()); super.screen.viewport.unproject(click); this.mousePointer.setPosition(click.x - this.mousePointer.getHeight() * 0.3f, click.y - this.mousePointer.getHeight() * 0.7f); //se apertar P o jogo acaba if (Gdx.input.isKeyPressed(Keys.P)) { super.challengeFailed(); }//from w w w . java 2s . c om // verifica se acertou a letr if (Gdx.input.justTouched()) { boolean letraEstaNaPalavra = false; // itera no array de letras for (int i = 0; i < letters.size; i++) { StructSprite sprite = letters.get(i); // se h interseo entre o retngulo do mouse e da letra, // o tiro acertou if (sprite.getSprite().getBoundingRectangle().contains(click)) { // remove a letra do array this.letters.removeValue(sprite, true); for (int j = 0; j < word.length(); j++) { //se a palavra tiver a letra, ela colocada no array de letras acertadas if (word.charAt(j) == sprite.getCaracter()) { Sprite s = new Sprite(sprite.getSprite()); s.setPosition(250 + j * 100, 320.0f); letrasCertas.add(s); letraEstaNaPalavra = true; qtdLetrasAcertadas--; somSucesso.play(); } } if (!letraEstaNaPalavra) { tentativas++; somDenteQuebrando.play(); } break; } } } }
From source file:br.cefetmg.games.minigames.Gallows.java
private void colocaLetrasNoArray() { for (int i = 0; i < 26; i++) { float posX, posY; if (i < 13) { posX = 350 + i * 50;//from www . ja va 2 s .c om posY = 200.0f; } else { posX = 350 + (i - 13) * 50; posY = 100.0f; } Sprite letra = new Sprite(letrasFrame.getKeyFrame(i)); letra.setPosition(posX, posY); StructSprite struct = new StructSprite(letra, i + 65); letters.add(struct); } }