private Sprite newSprite (AtlasRegion region) { if (region.packedWidth == region.originalWidth && region.packedHeight == region.originalHeight) { if (region.rotate) { Sprite sprite = new Sprite(region); sprite.setBounds(0, 0, region.getRegionHeight(), region.getRegionWidth()); sprite.rotate90(true); return sprite; } return new Sprite(region); } return new AtlasSprite(region); }
public void draw (Batch batch, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) { Color spriteColor = sprite.getColor(); temp.set(spriteColor); sprite.setColor(spriteColor.mul(batch.getColor())); sprite.setOrigin(originX, originY); sprite.setRotation(rotation); sprite.setScale(scaleX, scaleY); sprite.setBounds(x, y, width, height); sprite.draw(batch); sprite.setColor(temp); }
public void updateImageBackgroundPosSize (float x, float y, float width, float height) { if (bgImage != null) { bgImage.setPosition(x, y); bgImage.setSize(width, height); } } }
/** Creates a sprite with width, height, and texture region equal to the specified size, relative to specified sprite's texture * region. * @param srcWidth The width of the texture region. May be negative to flip the sprite when drawn. * @param srcHeight The height of the texture region. May be negative to flip the sprite when drawn. */ public Sprite (TextureRegion region, int srcX, int srcY, int srcWidth, int srcHeight) { setRegion(region, srcX, srcY, srcWidth, srcHeight); setColor(1, 1, 1, 1); setSize(Math.abs(srcWidth), Math.abs(srcHeight)); setOrigin(width / 2, height / 2); }
private void renderSingleLine () { String text = "Single Line"; float x = logoSprite.getX(); float y = logoSprite.getY(); float width = logoSprite.getWidth(); float height = logoSprite.getHeight(); layout.setText(font, text); x += width / 2 - layout.width / 2; y += height / 2 + layout.height / 2; font.draw(spriteBatch, text, x, y); }
private void createBodySprite() { bodySprite = null; RigidBodyModel model = Ctx.bodies.getSelectedModel(); if (model == null) return; TextureRegion region = Assets.inst().getRegion(model); if (region == null) return; bodySprite = new Sprite(region); bodySprite.setPosition(0, 0); bodySprite.setColor(1, 1, 1, 0.5f); float spRatio = bodySprite.getWidth() / bodySprite.getHeight(); bodySprite.setSize(1, 1 / spRatio); }
/** Creates a new drawable that renders the same as this drawable tinted the specified color. */ public SpriteDrawable tint (Color tint) { Sprite newSprite; if (sprite instanceof AtlasSprite) newSprite = new AtlasSprite((AtlasSprite)sprite); else newSprite = new Sprite(sprite); newSprite.setColor(tint); newSprite.setSize(getMinWidth(), getMinHeight()); SpriteDrawable drawable = new SpriteDrawable(newSprite); drawable.setLeftWidth(getLeftWidth()); drawable.setRightWidth(getRightWidth()); drawable.setTopHeight(getTopHeight()); drawable.setBottomHeight(getBottomHeight()); return drawable; } }
sprites3[i] = new Sprite(texture2, 32, 32); else sprites3[i] = new Sprite(texture, 32, 32); sprites3[i].setPosition(x, y); sprites3[i].setOrigin(16, 16); sprites3[i].setRotation(angle); sprites3[i].setScale(scale); spriteCache.add(sprites3[i]); sprites3[i].setRotation(angle); sprites3[i].setScale(scale); spriteCache.add(sprites3[i]);
public void draw(SpriteBatch batch) { for (Iterator<Sprite> iterator = enemies.iterator(); iterator.hasNext();) { Sprite drawEnemy = iterator.next(); drawEnemy.draw(batch); drawEnemy.translateY(deltaTime * movement); if (touched((drawEnemy.getX(),drawEnemy.getY(), drawEnemy.getWidth(),drawEnemy.getHeight())){ iterator.remove(); Pools.free(sprite); } } }
@Override public void create () { renderer = new ImmediateModeRenderer20(false, false, 0); spriteBatch = new SpriteBatch(); obj = new Sprite(new Texture(Gdx.files.internal("data/badlogicsmall.jpg"))); obj.setSize(40, 40); obj.setOriginCenter(); obj2 = new Sprite(new Texture(Gdx.files.internal("data/bobrgb888-32x32.png"))); obj2.setSize(40, 40); obj2.setOriginCenter(); ZIGZAG_SCALE = Gdx.graphics.getDensity() * 96; // 96DP float w = Gdx.graphics.getWidth() - obj.getWidth(); float h = Gdx.graphics.getHeight() - obj.getHeight(); paths.add(new Bezier<Vector2>(new Vector2(0, 0), new Vector2(w, h))); paths.add(new Bezier<Vector2>(new Vector2(0, 0), new Vector2(0, h), new Vector2(w, h))); paths.add(new Bezier<Vector2>(new Vector2(0, 0), new Vector2(w, 0), new Vector2(0, h), new Vector2(w, h))); Vector2 cp[] = new Vector2[] {new Vector2(0, 0), new Vector2(w * 0.25f, h * 0.5f), new Vector2(0, h), new Vector2(w * 0.5f, h * 0.75f), new Vector2(w, h), new Vector2(w * 0.75f, h * 0.5f), new Vector2(w, 0), new Vector2(w * 0.5f, h * 0.25f)}; paths.add(new BSpline<Vector2>(cp, 3, true)); paths.add(new CatmullRomSpline<Vector2>(cp, true)); pathLength = paths.get(currentPath).approxLength(500); avg_speed = speed * pathLength; Gdx.input.setInputProcessor(this); }
public void create () { texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); Sprite sprite = new Sprite(texture); sprite.setSize(tileSize, tileSize); cache = new SpriteCache(1000, false); for (int y = 0; y < tileMapHeight; y++) { cache.beginCache(); for (int x = 0; x < tileMapWidth; x++) { sprite.setPosition(x * tileSize, y * tileSize); cache.add(sprite); } cache.endCache(); sprite.rotate90(true); } }
@Override public void addPos(float x, float y) { super.addPos(x, y); sprite.setPosition(sprite.getX() + x, sprite.getY() + y); }
float prevSpriteHeight = particle.getHeight(); particle.setRegion(sprite); particle.setSize(sprite.getWidth(), sprite.getHeight()); particle.setOrigin(sprite.getOriginX(), sprite.getOriginY()); particle.translate((prevSpriteWidth - sprite.getWidth()) / 2, (prevSpriteHeight - sprite.getHeight()) / 2); particle.frame = frame;
@Override public void create () { Gdx.input.setInputProcessor(new InputAdapter() { public boolean touchDown (int x, int y, int pointer, int newParam) { renderMode = (renderMode + 1) % 4; return false; } }); spriteBatch = new SpriteBatch(); spriteBatch.setProjectionMatrix(new Matrix4().setToOrtho(0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, 0, 1)); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); logoSprite = new Sprite(texture); logoSprite.flip(false, true); logoSprite.setPosition(0, 320 - 256); logoSprite.setColor(1, 1, 1, 0.5f); font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), Gdx.files.internal("data/verdana39.png"), true); cache1 = font.newFontCache(); cache2 = font.newFontCache(); cache3 = font.newFontCache(); cache4 = font.newFontCache(); cache5 = font.newFontCache(); createCaches("cached", cache1, cache2, cache3, cache4, cache5); font.getData().setScale(1.33f); cacheScaled1 = font.newFontCache(); cacheScaled2 = font.newFontCache(); cacheScaled3 = font.newFontCache(); cacheScaled4 = font.newFontCache(); cacheScaled5 = font.newFontCache(); createCaches("cache scaled", cacheScaled1, cacheScaled2, cacheScaled3, cacheScaled4, cacheScaled5); }
@Override public void create () { batch = new SpriteBatch(); font = new BitmapFont(); stage = new Stage(new ScalingViewport(Scaling.fit, 24, 12)); regions = new TextureRegion[8 * 8]; sprites = new Sprite[24 * 12]; texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { regions[x + y * 8] = new TextureRegion(texture, x * 32, y * 32, 32, 32); } } Random rand = new Random(); for (int y = 0, i = 0; y < 12; y++) { for (int x = 0; x < 24; x++) { Image img = new Image(regions[rand.nextInt(8 * 8)]); img.setBounds(x, y, 1, 1); stage.addActor(img); sprites[i] = new Sprite(regions[rand.nextInt(8 * 8)]); sprites[i].setPosition(x, y); sprites[i].setSize(1, 1); i++; } } }
sprites3[i] = new Sprite(texture2, 32, 32); else sprites3[i] = new Sprite(texture, 32, 32); sprites3[i].setPosition(x, y); sprites3[i].setOrigin(16, 16);
@Override public void create () { Preferences pref = Gdx.app.getPreferences("test"); boolean resultb = pref.getBoolean("test"); int resulti = pref.getInteger("test"); shader = new ShaderProgram(Gdx.files.internal("data/shaders/shader-vs.glsl"), Gdx.files.internal("data/shaders/shader-fs.glsl")); if (!shader.isCompiled()) throw new GdxRuntimeException(shader.getLog()); mesh = new Mesh(VertexDataType.VertexBufferObject, true, 6, 0, VertexAttribute.Position(), VertexAttribute.TexCoords(0)); mesh.setVertices(new float[] {-0.5f, -0.5f, 0, 0, 1, 0.5f, -0.5f, 0, 1, 1, 0.5f, 0.5f, 0, 1, 0, 0.5f, 0.5f, 0, 1, 0, -0.5f, 0.5f, 0, 0, 0, -0.5f, -0.5f, 0, 0, 1}); texture = new Texture(new Pixmap(Gdx.files.internal("data/badlogic.jpg")), true); texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear); String params = Gdx.files.internal("data/gwttestparams.txt").readString(); numSprites = Integer.parseInt(params); batch = new SpriteBatch(); positions = new ArrayList<Vector2>(); for (int i = 0; i < numSprites; i++) { positions.add(new Vector2(MathUtils.random() * Gdx.graphics.getWidth(), MathUtils.random() * Gdx.graphics.getHeight())); } sprite = new Sprite(texture); sprite.setSize(64, 64); sprite.setOrigin(32, 32); font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); cache = font.newFontCache(); cache.setColor(Color.RED); cache.setText("This is a Test", 0, 0); atlas = new TextureAtlas(Gdx.files.internal("data/pack")); }