Java Code Examples for com.badlogic.gdx.graphics.g2d.Sprite#setBounds()
The following examples show how to use
com.badlogic.gdx.graphics.g2d.Sprite#setBounds() .
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: MapLoader.java From Bomberman_libGdx with MIT License | 5 votes |
protected Sprite createGroundSprite() { TextureRegion textureRegion = tileTextureAtlas.findRegion("ground"); Sprite sprite = new Sprite(); sprite.setRegion(textureRegion); sprite.setBounds(0, 0, 1, 1); return sprite; }
Example 2
Source File: PlayScreen.java From Pacman_libGdx with MIT License | 4 votes |
@Override public void show() { camera = new OrthographicCamera(); viewport = new FitViewport(WIDTH, HEIGHT, camera); camera.translate(WIDTH / 2, HEIGHT / 2); camera.update(); batch = new SpriteBatch(); playerSystem = new PlayerSystem(); ghostSystem = new GhostSystem(); movementSystem = new MovementSystem(); pillSystem = new PillSystem(); animationSystem = new AnimationSystem(); renderSystem = new RenderSystem(batch); stateSystem = new StateSystem(); engine = new Engine(); engine.addSystem(playerSystem); engine.addSystem(ghostSystem); engine.addSystem(pillSystem); engine.addSystem(movementSystem); engine.addSystem(stateSystem); engine.addSystem(animationSystem); engine.addSystem(renderSystem); // box2d world = new World(Vector2.Zero, true); world.setContactListener(new WorldContactListener()); box2DDebugRenderer = new Box2DDebugRenderer(); showBox2DDebuggerRenderer = false; // box2d light rayHandler = new RayHandler(world); rayHandler.setAmbientLight(ambientLight); // load map tiledMap = new TmxMapLoader().load("map/map.tmx"); tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap, 1 / 16f, batch); new WorldBuilder(tiledMap, engine, world, rayHandler).buildAll(); stageViewport = new FitViewport(WIDTH * 20, HEIGHT * 20); stage = new Stage(stageViewport, batch); font = new BitmapFont(Gdx.files.internal("fonts/army_stencil.fnt")); Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE); Label scoreTextLabel = new Label("SCORE", labelStyle); scoreTextLabel.setPosition(WIDTH * 1, HEIGHT * 19); stage.addActor(scoreTextLabel); Label hightScoreTextLabel = new Label("High Score", labelStyle); hightScoreTextLabel.setPosition(WIDTH * 14, HEIGHT * 19); stage.addActor(hightScoreTextLabel); scoreLabel = new Label("0", labelStyle); scoreLabel.setPosition(WIDTH * 1.5f, HEIGHT * 18.2f); stage.addActor(scoreLabel); highScoreLabel = new Label("0", labelStyle); highScoreLabel.setPosition(WIDTH * 16.5f, HEIGHT * 18.2f); stage.addActor(highScoreLabel); gameOverLabel = new Label(" - Game Over -\n Press Enter to continue", labelStyle); gameOverLabel.setPosition(WIDTH * 4.3f, HEIGHT * 9f); gameOverLabel.setVisible(false); stage.addActor(gameOverLabel); TextureAtlas textureAtlas = GameManager.instance.assetManager.get("images/actors.pack", TextureAtlas.class); pacmanSprite = new Sprite(new TextureRegion(textureAtlas.findRegion("Pacman"), 16, 0, 16, 16)); pacmanSprite.setBounds(8f, 21.5f, 16 / GameManager.PPM, 16 / GameManager.PPM); stringBuilder = new StringBuilder(); changeScreen = false; }
Example 3
Source File: Hud.java From Bomberman_libGdx with MIT License | 4 votes |
public Hud(SpriteBatch batch, float width, float height) { this.batch = batch; AssetManager assetManager = GameManager.getInstance().getAssetManager(); textureAtlas = assetManager.get("img/actors.pack", TextureAtlas.class); bombSprite = new Sprite(new TextureRegion(textureAtlas.findRegion("Bomb"), 0, 0, 16, 16)); bombSprite.setBounds(15.0f, 11.5f, 1, 1); Pixmap pixmap = new Pixmap(5, 15, Pixmap.Format.RGBA8888); pixmap.setColor(240.0f / 255.0f, 128 / 255.0f, 0, 1.0f); pixmap.fill(); bgTexture = new Texture(pixmap); pixmap.setColor(1, 1, 1, 1); pixmap.fill(); bombTimerTexture = new Texture(pixmap); pixmap.dispose(); bombTimerSprite = new Sprite(bombTimerTexture); bombTimerSprite.setBounds(16f, 12.5f, 3.0f, 0.2f); TextureRegion itemTextureRegion = textureAtlas.findRegion("Items"); powerSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 1, 0, 16, 16)); powerSprite.setBounds(leftAlignment, 9.0f, 1, 1); speedSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 2, 0, 16, 16)); speedSprite.setBounds(leftAlignment, 8.0f, 1, 1); kickSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 3, 0, 16, 16)); kickSprite.setBounds(leftAlignment, 7.0f, 1, 1); remoteSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 4, 0, 16, 16)); remoteSprite.setBounds(leftAlignment, 6.0f, 1, 1); Array<TextureRegion> keyFrames = new Array<TextureRegion>(); for (int i = 0; i < 5; i++) { keyFrames.add(new TextureRegion(textureAtlas.findRegion("Bomberman_big"), 32 * i, 0, 32, 48)); } bigBombermanAnimation = new Animation(0.2f, keyFrames, Animation.PlayMode.LOOP_PINGPONG); bigBombermanSprite = new Sprite(bigBombermanAnimation.getKeyFrame(0)); bigBombermanSprite.setBounds(17.5f, 0.5f, 2f, 3f); stateTime = 0; FitViewport viewport = new FitViewport(width * SCALE, height * SCALE); stage = new Stage(viewport, batch); font = new BitmapFont(Gdx.files.internal("fonts/foo.fnt")); Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE); fpsLabel = new Label("FPS:", labelStyle); fpsLabel.setFontScale(0.3f); fpsLabel.setPosition(16 * SCALE, -0.8f * SCALE); fpsLabel.setVisible(showFPS); levelLabel = new Label("Level", labelStyle); levelLabel.setPosition(15.5f * SCALE, 3 * SCALE); levelLabel.setFontScale(0.4f); playerLivesLabel = new Label("" + GameManager.playerLives, labelStyle); playerLivesLabel.setFontScale(0.5f); playerLivesLabel.setPosition(16.8f * SCALE, 12.8f * SCALE); Image bombermanImage = new Image(new TextureRegion(textureAtlas.findRegion("Items"), 16 * 5, 0, 16, 16)); bombermanImage.setPosition(leftAlignment * SCALE, 13.5f * SCALE); xLabel = new Label("X", labelStyle); xLabel.setFontScale(0.4f); xLabel.setPosition(16.8f * SCALE, 6.3f * SCALE); zLabel = new Label("Z", labelStyle); zLabel.setFontScale(0.4f); zLabel.setPosition(16.8f * SCALE, 5.3f * SCALE); stage.addActor(fpsLabel); stage.addActor(levelLabel); stage.addActor(playerLivesLabel); stage.addActor(bombermanImage); stage.addActor(xLabel); stage.addActor(zLabel); stringBuilder = new StringBuilder(); }
Example 4
Source File: FluidSimulatorLiquid.java From fluid-simulator-v2 with Apache License 2.0 | 4 votes |
private void createWorld() { dropRadius = 0.1f + dropRadiusK; dropRadiusPixel = (int) (dropRadius * PARTICLE_SIZE); dropRadiusPixel2 = dropRadiusPixel * dropRadiusPixel; dropTexture = new Texture("data/fluid_drop_64.png"); dropTexture2 = new Texture("data/fluid_drop_64.png"); dropSprite = new Sprite(dropTexture); dropSprite.setSize(dropRadiusPixel, dropRadiusPixel); if (IS_DESKTOP) { disposableParticles = new ArrayList<Particle>(SIZE); } defaultShader = new ShaderProgram(Gdx.files.internal("data/shaders/default.vert").readString(), Gdx.files.internal("data/shaders/default.frag").readString()); if (!defaultShader.isCompiled()) { Gdx.app.log("SHADER_LOG", "couldn't compile default shader: " + defaultShader.getLog()); } defaultIMShader = new ShaderProgram(Gdx.files.internal("data/shaders/defaultim.vert").readString(), Gdx.files.internal("data/shaders/defaultim.frag").readString()); if (!defaultIMShader.isCompiled()) { Gdx.app.log("SHADER_LOG", "couldn't compile default IM shader: " + defaultIMShader.getLog()); } ShaderProgram.pedantic = false; refractionShader = new ShaderProgram(Gdx.files.internal("data/shaders/refract.vert").readString(), Gdx.files.internal("data/shaders/refract.frag").readString()); if (!refractionShader.isCompiled()) { Gdx.app.log("SHADER_LOG", "couldn't compile refraction shader: " + refractionShader.getLog()); } irt.setShader(defaultIMShader); bgTexture = new Texture("data/bg.png"); glossMapTexture = new Texture("data/gloss_map2.png"); displacementMap = new Texture("data/water1.png"); displacementMap2 = new Texture("data/water2.png"); bgSprite = new Sprite(bgTexture); bgSprite.setBounds(0, -1, Gdx.graphics.getWidth(), Gdx.graphics.getHeight() + 1); // On Android populate directly if (!IS_DESKTOP) { for (float j = INITIAL_HEIGHT + hpadding + 2; j < BOX_HEIGHT - 2; j += 5.5f) { for (float i = -BOX_WIDTH / 3; i < BOX_WIDTH / 3; i += 5.5f) { particles.add(new Particle(i, j, prevHash++)); tempParticle = particles.get(particles.size() - 1); tempParticle.type = (emitType); if (particles.size() >= ANDROID_SIZE) break; } if (particles.size() >= ANDROID_SIZE) break; } } // createPiece(17, 0, 150, 0, 0, 0, false, true, true); createPiece(17, 100, 240, 0, 0, 0, false, true, true); // Boxes createPiece(6, 0, 160, 0, 0, 0, false, false, true); createPiece(14, -150, 200, 0, 0, 0, false, false, true); createPiece(14, 0, 140, 0, 0, 0, false, false, true); createPiece(14, -170, 60, 90, 0, 0, false, false, true); // Ball createPiece(4, 100, 100, 0, -20, 0, false, false, true); // Portals createPortalIn(-140, 65, 0, 0); createPortalOut(-140, 240, 0, 0); // Ground cage createPiece(18, -BOX_WIDTH/2 + 7, BOX_HEIGHT/2, 0, 0, 0, 0.2f, 0.5f, false, false, true); createPiece(18, BOX_WIDTH/2 - 10, BOX_HEIGHT/2, 0, 0, 0, 0.2f, 0.5f, false, false, true); createPiece(18, 0, INITIAL_HEIGHT, 90, 0, 0, 0.2f, 0.5f, false, false, true); createPiece(18, 0, BOX_HEIGHT - 10, 90, 0, 0, 0.2f, 0.5f, false, false, true); // Ground body for mousejoint BodyDef bodyDef = new BodyDef(); // bodyDef.type = BodyType.StaticBody; groundBody = world.createBody(bodyDef); }
Example 5
Source File: FluidSimulator.java From fluid-simulator-v2 with Apache License 2.0 | 4 votes |
private void createWorld() { dropRadius = 0.1f + dropRadiusK; dropRadiusPixel = (int) (dropRadius * PARTICLE_SIZE); dropRadiusPixel2 = dropRadiusPixel * dropRadiusPixel; dropTexture = new Texture("data/fluid_drop_64.png"); dropTexture2 = new Texture("data/fluid_drop_64.png"); dropSprite = new Sprite(dropTexture); dropSprite.setSize(dropRadiusPixel, dropRadiusPixel); if (IS_DESKTOP) { disposableParticles = new ArrayList<Particle>(SIZE); } defaultShader = new ShaderProgram(Gdx.files.internal("data/shaders/default.vert").readString(), Gdx.files.internal("data/shaders/default.frag").readString()); if (!defaultShader.isCompiled()) { Gdx.app.log("SHADER_LOG", "couldn't compile default shader: " + defaultShader.getLog()); } defaultIMShader = new ShaderProgram(Gdx.files.internal("data/shaders/defaultim.vert").readString(), Gdx.files.internal("data/shaders/defaultim.frag").readString()); if (!defaultIMShader.isCompiled()) { Gdx.app.log("SHADER_LOG", "couldn't compile default IM shader: " + defaultIMShader.getLog()); } ShaderProgram.pedantic = false; refractionShader = new ShaderProgram(Gdx.files.internal("data/shaders/refract.vert").readString(), Gdx.files.internal("data/shaders/refract.frag").readString()); if (!refractionShader.isCompiled()) { Gdx.app.log("SHADER_LOG", "couldn't compile refraction shader: " + refractionShader.getLog()); } irt.setShader(defaultIMShader); bgTexture = new Texture("data/bg.png"); glossMapTexture = new Texture("data/gloss_map2.png"); displacementMap = new Texture("data/water1.png"); displacementMap2 = new Texture("data/water2.png"); bgSprite = new Sprite(bgTexture); bgSprite.setBounds(0, -1, Gdx.graphics.getWidth(), Gdx.graphics.getHeight() + 1); // On Android populate directly if (!IS_DESKTOP) { for (float j = INITIAL_HEIGHT + hpadding + 2; j < BOX_HEIGHT - 2; j += 5.5f) { for (float i = -BOX_WIDTH / 3; i < BOX_WIDTH / 3; i += 5.5f) { particles.add(new Particle(i, j, prevHash++)); tempParticle = particles.get(particles.size() - 1); tempParticle.type = (emitType); if (particles.size() >= ANDROID_SIZE) break; } if (particles.size() >= ANDROID_SIZE) break; } } // createPiece(17, 0, 150, 0, 0, 0, false, true, true); createPiece(17, 100, 240, 0, 0, 0, false, true, true); // createPortalIn(-140, 65, 0, 0, false, true); // createPortalOut(-140, 220, 0, 0, false, true); // Boxes createPiece(6, 0, 160, 0, 0, 0, false, false, true); createPiece(14, -150, 200, 0, 0, 0, false, false, true); createPiece(14, 0, 140, 0, 0, 0, false, false, true); createPiece(14, -170, 60, 90, 0, 0, false, false, true); // Ball createPiece(4, 100, 100, 0, -20, 0, false, false, true); // Ground cage createPiece(18, -BOX_WIDTH/2 + 7, BOX_HEIGHT/2, 0, 0, 0, 0.2f, 0.5f, false, false, true); createPiece(18, BOX_WIDTH/2 - 10, BOX_HEIGHT/2, 0, 0, 0, 0.2f, 0.5f, false, false, true); createPiece(18, 0, INITIAL_HEIGHT, 90, 0, 0, 0.2f, 0.5f, false, false, true); createPiece(18, 0, BOX_HEIGHT - 10, 90, 0, 0, 0.2f, 0.5f, false, false, true); // Ground body for mousejoint BodyDef bodyDef = new BodyDef(); // bodyDef.type = BodyType.StaticBody; groundBody = world.createBody(bodyDef); }
Example 6
Source File: FluidSimulatorMPM.java From fluid-simulator-v2 with Apache License 2.0 | 4 votes |
private void createWorld() { dropRadius = 0.1f + dropRadiusK; dropRadiusPixel = (int) (dropRadius * PARTICLE_SIZE); dropRadiusPixel2 = dropRadiusPixel * dropRadiusPixel; dropTexture = new Texture("data/fluid_drop_64.png"); dropTexture2 = new Texture("data/fluid_drop_64.png"); dropSprite = new Sprite(dropTexture); dropSprite.setSize(dropRadiusPixel, dropRadiusPixel); if (IS_DESKTOP) { disposableParticles = new ArrayList<Particle>(SIZE); } defaultShader = new ShaderProgram(Gdx.files.internal("data/shaders/default.vert").readString(), Gdx.files.internal("data/shaders/default.frag").readString()); if (!defaultShader.isCompiled()) { Gdx.app.log("SHADER_LOG", "couldn't compile default shader: " + defaultShader.getLog()); } defaultIMShader = new ShaderProgram(Gdx.files.internal("data/shaders/defaultim.vert").readString(), Gdx.files.internal("data/shaders/defaultim.frag").readString()); if (!defaultIMShader.isCompiled()) { Gdx.app.log("SHADER_LOG", "couldn't compile default IM shader: " + defaultIMShader.getLog()); } ShaderProgram.pedantic = false; refractionShader = new ShaderProgram(Gdx.files.internal("data/shaders/refract.vert").readString(), Gdx.files.internal("data/shaders/refract.frag").readString()); if (!refractionShader.isCompiled()) { Gdx.app.log("SHADER_LOG", "couldn't compile refraction shader: " + refractionShader.getLog()); } irt.setShader(defaultIMShader); bgTexture = new Texture("data/bg.png"); glossMapTexture = new Texture("data/gloss_map2.png"); displacementMap = new Texture("data/water1.png"); displacementMap2 = new Texture("data/water2.png"); bgSprite = new Sprite(bgTexture); bgSprite.setBounds(0, -1, Gdx.graphics.getWidth(), Gdx.graphics.getHeight() + 1); // createPiece(17, 0, 150, 0, 0, 0, false, true, true); createPiece(17, 100, 240, 0, 0, 0, false, true, true); // createPortalIn(-140, 65, 0, 0, false, true); // createPortalOut(-140, 220, 0, 0, false, true); // Boxes createPiece(6, 0, 160, 0, 0, 0, false, false, true); createPiece(14, -150, 200, 0, 0, 0, false, false, true); createPiece(14, 0, 140, 0, 0, 0, false, false, true); createPiece(14, -170, 60, 90, 0, 0, false, false, true); // Ball createPiece(4, 100, 100, 0, -20, 0, false, false, true); // Ground cage createPiece(18, -BOX_WIDTH/2 + 7, BOX_HEIGHT/2, 0, 0, 0, 0.2f, 0.5f, false, false, true); createPiece(18, BOX_WIDTH/2 - 10, BOX_HEIGHT/2, 0, 0, 0, 0.2f, 0.5f, false, false, true); createPiece(18, 0, INITIAL_HEIGHT, 90, 0, 0, 0.2f, 0.5f, false, false, true); createPiece(18, 0, BOX_HEIGHT - 10, 90, 0, 0, 0.2f, 0.5f, false, false, true); // Ground body for mousejoint BodyDef bodyDef = new BodyDef(); // bodyDef.type = BodyType.StaticBody; groundBody = world.createBody(bodyDef); }