public void updateImageBackgroundPosSize (float x, float y, float width, float height) { if (bgImage != null) { bgImage.setPosition(x, y); bgImage.setSize(width, height); } } }
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. * @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 (Texture texture, int srcX, int srcY, int srcWidth, int srcHeight) { if (texture == null) throw new IllegalArgumentException("texture cannot be null."); this.texture = texture; setRegion(srcX, srcY, srcWidth, srcHeight); setColor(1, 1, 1, 1); setSize(Math.abs(srcWidth), Math.abs(srcHeight)); setOrigin(width / 2, height / 2); }
/** Creates a sprite with width, height, and texture region equal to the specified size. * @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 (Texture texture, int srcX, int srcY, int srcWidth, int srcHeight) { if (texture == null) throw new IllegalArgumentException("texture cannot be null."); this.texture = texture; setRegion(srcX, srcY, srcWidth, srcHeight); setColor(1, 1, 1, 1); setSize(Math.abs(srcWidth), Math.abs(srcHeight)); setOrigin(width / 2, height / 2); }
/** 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); }
/** 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); }
public boolean keyUp (int keycode) { if (keycode == Keys.UP) { badlogicSmall.flip(false, true); } else if (keycode == Keys.RIGHT) { badlogicSmall.flip(true, false); } else if (keycode == Keys.LEFT) { badlogicSmall.setSize(512, 512); } else if (keycode == Keys.DOWN) { badlogicSmall.rotate90(true); } return super.keyUp(keycode); } });
/** Creates a sprite based on a specific TextureRegion, the new sprite's region is a copy of the parameter region - altering one * does not affect the other */ public Sprite (TextureRegion region) { setRegion(region); setColor(1, 1, 1, 1); setSize(region.getRegionWidth(), region.getRegionHeight()); setOrigin(width / 2, height / 2); }
@Override public void render () { Gdx.gl.glClearColor(0, 1, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); spriteBatch.begin(); logoSprite.setSize(256, 256); logoSprite.draw(spriteBatch); spriteBatch.end(); }
/** Creates a sprite based on a specific TextureRegion, the new sprite's region is a copy of the parameter region - altering one * does not affect the other */ public Sprite (TextureRegion region) { setRegion(region); setColor(1, 1, 1, 1); setSize(region.getRegionWidth(), region.getRegionHeight()); setOrigin(width / 2, height / 2); }
@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++; } } }
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); } }
/** 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; } }
/** Creates a new drawable that renders the same as this drawable tinted the specified color. */ public Drawable tint (Color tint) { Sprite sprite; if (region instanceof AtlasRegion) sprite = new AtlasSprite((AtlasRegion)region); else sprite = new Sprite(region); sprite.setColor(tint); sprite.setSize(getMinWidth(), getMinHeight()); SpriteDrawable drawable = new SpriteDrawable(sprite); drawable.setLeftWidth(getLeftWidth()); drawable.setRightWidth(getRightWidth()); drawable.setTopHeight(getTopHeight()); drawable.setBottomHeight(getBottomHeight()); return drawable; } }
/** Creates a new drawable that renders the same as this drawable tinted the specified color. */ public Drawable tint (Color tint) { Sprite sprite; if (region instanceof AtlasRegion) sprite = new AtlasSprite((AtlasRegion)region); else sprite = new Sprite(region); sprite.setColor(tint); sprite.setSize(getMinWidth(), getMinHeight()); SpriteDrawable drawable = new SpriteDrawable(sprite); drawable.setLeftWidth(getLeftWidth()); drawable.setRightWidth(getRightWidth()); drawable.setTopHeight(getTopHeight()); drawable.setBottomHeight(getBottomHeight()); return drawable; } }
/** 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; } }
@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")); }
@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); }
/** Creates a sprite with width, height, and texture region equal to the specified size. * @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 (Texture texture, int srcX, int srcY, int srcWidth, int srcHeight) { if (texture == null) throw new IllegalArgumentException("texture cannot be null."); this.texture = texture; setRegion(srcX, srcY, srcWidth, srcHeight); setColor(1, 1, 1, 1); setSize(Math.abs(srcWidth), Math.abs(srcHeight)); setOrigin(width / 2, height / 2); }
/** 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); }