Java Code Examples for com.badlogic.gdx.graphics.g2d.Sprite#setSize()
The following examples show how to use
com.badlogic.gdx.graphics.g2d.Sprite#setSize() .
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: ClientBomb.java From killingspree with MIT License | 6 votes |
public ClientBomb(short id, float x, float y, WorldRenderer renderer) { super(id, x, y, renderer); markForDispose = false; sprite = new Sprite(AssetLoader.instance.getTexture("sprites/bomb.png")); sprite.setSize(ServerBomb.RADIUS + 5, ServerBomb.RADIUS + 5); sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2); sprite.setPosition(x - sprite.getWidth() / 2, y - sprite.getHeight() / 2); deadTimer = 0f; Texture explodeTexture = AssetLoader.instance. getTexture("sprites/explosion.png"); explode = new Animation(0.03f, TextureRegion.split(explodeTexture, explodeTexture.getWidth()/7, explodeTexture.getHeight())[0]); }
Example 2
Source File: ClientFrog.java From killingspree with MIT License | 5 votes |
public ClientFrog(short id, float x, float y, WorldRenderer renderer) { super(id, x, y, renderer); markForDispose = false; Texture texture = AssetLoader.instance.getTexture("sprites/frog.png"); sprite = new Sprite(texture); walk = new Animation(0.25f, TextureRegion.split(texture, texture.getWidth()/2, texture.getHeight())[0]); walk.setPlayMode(Animation.PlayMode.LOOP); sprite.setSize(ServerFrog.WIDTH + 5f, ServerFrog.HEIGHT + 5f); }
Example 3
Source File: ClientPlayer.java From killingspree with MIT License | 5 votes |
public ClientPlayer(short id, float x, float y, WorldRenderer renderer) { super(id, x, y, renderer); markForDispose = false; Texture texture = AssetLoader.instance.getTexture("sprites/player.png"); sprite = new Sprite(texture); gunSprite = new Sprite(AssetLoader.instance.getTexture("sprites/arrow.png")); gunSprite.setOrigin(gunSprite.getWidth()/2, gunSprite.getHeight()/2); walk = new Animation(0.05f, TextureRegion.split(texture, texture.getWidth()/10, texture.getHeight())[0]); walk.setPlayMode(Animation.PlayMode.LOOP); walkDuration = 0; gunSprite.setSize(40, 6); gunSprite.setOrigin(gunSprite.getWidth()/2, gunSprite.getHeight()/2); gunSprite.setAlpha(0.7f); }
Example 4
Source File: ClientBullet.java From killingspree with MIT License | 5 votes |
public ClientBullet(short id, float x, float y, WorldRenderer renderer) { super(id, x, y, renderer); markForDispose = false; sprite = new Sprite(AssetLoader.instance.getTexture("sprites/bullet.png")); sprite.setSize(ServerArrow.RADIUS * 4 , ServerArrow.RADIUS * 1.5f); sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2); sprite.setPosition(x - sprite.getWidth() / 2, y - sprite.getHeight() / 2); renderer.audioPlayer.shoot(); }
Example 5
Source File: ClientBlob.java From killingspree with MIT License | 5 votes |
public ClientBlob(short id, float x, float y, WorldRenderer renderer) { super(id, x, y, renderer); markForDispose = false; Texture texture = AssetLoader.instance.getTexture("sprites/blob.png"); sprite = new Sprite(texture); walk = new Animation(0.25f, TextureRegion.split(texture, texture.getWidth()/2, texture.getHeight())[0]); walk.setPlayMode(Animation.PlayMode.LOOP); sprite.setSize(ServerBlob.WIDTH + 5f, ServerBlob.HEIGHT); deadTimer = 2f; }
Example 6
Source File: ClientArrow.java From killingspree with MIT License | 5 votes |
public ClientArrow(short id, float x, float y, WorldRenderer renderer) { super(id, x, y, renderer); markForDispose = false; sprite = new Sprite(AssetLoader.instance.getTexture("sprites/arrow.png")); sprite.setSize(ServerArrow.RADIUS * 10 , ServerArrow.RADIUS * 2.5f); sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2); sprite.setPosition(x - sprite.getWidth() / 2, y - sprite.getHeight() / 2); }
Example 7
Source File: ClientFly.java From killingspree with MIT License | 5 votes |
public ClientFly(short id, float x, float y, WorldRenderer renderer) { super(id, x, y, renderer); markForDispose = false; Texture texture = AssetLoader.instance.getTexture("sprites/fly.png"); sprite = new Sprite(texture); walk = new Animation(0.25f, TextureRegion.split(texture, texture.getWidth()/2, texture.getHeight())[0]); walk.setPlayMode(Animation.PlayMode.LOOP); sprite.setSize(ServerBlob.WIDTH + 5f, ServerFly.HEIGHT); }
Example 8
Source File: WrongWay.java From uracer-kotd with Apache License 2.0 | 5 votes |
public WrongWay () { sign = new Sprite(Art.wrongWay); float scale = 0.4f; w = Art.wrongWay.getWidth() * scale; h = Art.wrongWay.getHeight() * scale; offX = w / 2; offY = h / 2; sign.setSize(w, h); sign.setOrigin(offX, offY); sign.flip(false, true); bfAlpha = new BoxedFloat(0); isShown = false; }
Example 9
Source File: FluidSimulatorSPH.java From fluid-simulator-v2 with Apache License 2.0 | 5 votes |
private void createWorld() { dropRadius = 0.1f + dropRadiusK; dropRadiusPixel = (int) (dropRadius * PARTICLE_SIZE); dropRadiusPixel2 = dropRadiusPixel * dropRadiusPixel; if (IS_DESKTOP) { // dropTexture = new Texture("data/fluid_drop_red_64.png"); dropTexture = new Texture("data/fluid_drop_64.png"); dropTexture2 = new Texture("data/fluid_drop_blue_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 scene shader: " + defaultShader.getLog()); } immediateRenderer = new ImmediateModeRenderer20(50000, false, true, 0); // On Android populate directly if (!IS_DESKTOP) { for (float j = INITIAL_HEIGHT + hpadding + 2; j < WORLD_HEIGHT - 2; j += 1.0f) { for (float i = -WORLD_WIDTH / 3; i < WORLD_WIDTH / 3; i += 1.0f) { particles.add(new Particle(i, j)); tempParticle = particles.get(particles.size() - 1); tempParticle.type = (emitType); if (particles.size() >= ANDROID_SIZE) return; } } } }
Example 10
Source File: ClientGrenade.java From seventh with GNU General Public License v2.0 | 5 votes |
/** * */ public ClientGrenade(ClientGame game, Vector2f pos, Type grenadeType) { super(game, pos); this.grenadeType = grenadeType; sprite = new Sprite(grenadeType==Type.SMOKE_GRENADE ? Art.smokeGrenadeImage : Art.fragGrenadeImage); sprite.setSize(16, 16); sprite.setOrigin(8, 8); sprite.flip(false, true); }
Example 11
Source File: TextureUtil.java From seventh with GNU General Public License v2.0 | 5 votes |
/** * Resizes the image * * @param image * @param width * @param height * @return */ public static Sprite resizeImage(TextureRegion image, int width, int height) { Sprite sprite = new Sprite(image); sprite.setSize(width, height); // TextureRegion region = new TextureRegion(image); // region.setRegionWidth(width); // region.setRegionHeight(height); return sprite; }
Example 12
Source File: PlayerSprite.java From seventh with GNU General Public License v2.0 | 5 votes |
private void setTextureRegion(Sprite sprite, TextureRegion region) { sprite.setTexture(region.getTexture()); sprite.setRegion(region); sprite.setSize(region.getRegionWidth(), region.getRegionHeight()); sprite.setOrigin(region.getRegionWidth()/2f, region.getRegionHeight()/2f); sprite.flip(false, true); }
Example 13
Source File: WeaponClassDialogView.java From seventh with GNU General Public License v2.0 | 4 votes |
private TextureRegion scale(TextureRegion tex) { Sprite sprite = new Sprite(tex); sprite.setSize(110, 45); return sprite; }
Example 14
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); }
Example 15
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 16
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 17
Source File: SpritesSample.java From Codelabs with MIT License | 4 votes |
@Override public void show() { /* * This line is found in every sample but is not necessary for the * sample functionality. calls Sample.show() method. That method set the * sample to receive all touch and key input events. Also prevents the * app from be closed whenever the user press back button and instead * returns to main menu. */ super.show(); /* * Create world with a common gravity vector (9.81 m/s2 downwards force) * and tell world that we want objects to sleep. This last value * conserves CPU usage. */ world = new World(new Vector2(0, -9.81f), true); /* Create renderer */ debugRenderer = new Box2DDebugRenderer(); batch = new SpriteBatch(); /* * Define camera viewport. Box2D uses meters internally so the camera * must be defined also in meters. We set a desired width and adjust * height to different resolutions. */ camera = new OrthographicCamera(20, 20 * (Gdx.graphics.getHeight() / (float) Gdx.graphics .getWidth())); /* * Next line must remain commented because we do this in its parent (See * Sample class). In case you are not using Sample class, uncomment this * line to set input processor to handle events. */ // Gdx.input.setInputProcessor(this); /* Create the box */ Shape shape = Box2DFactory.createBoxShape(1.5f, 1.5f, new Vector2(0, 0), 0); FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 0.3f, 0.5f, 0.5f, false); box = Box2DFactory.createBody(world, BodyType.DynamicBody, fixtureDef, new Vector2(0, 0)); /* Create the walls */ Box2DFactory.createWalls(world, camera.viewportWidth, camera.viewportHeight, 1); /* Set box texture */ sprite = new Sprite(new Texture("data/images/crab.png")); /* * Set the size of the sprite. We have to remember that we are not * working in pixels, but with meters. The size of the sprite will be * the same as the size of the box; 2 meter wide, 2 meters tall. */ sprite.setSize(3, 3); /* * Sets the origin in relation to the sprite's position for scaling and * rotation. */ sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2); /* Set sprite as a user data of the body to draw it in each render step */ box.setUserData(sprite); /* Instantiate the array of bodies that will be used during render step */ worldBodies = new Array<Body>(); }