public FadingSprite(Sprite sprite, float x, float y, float minAmount, float maxAmount, float subAmount, float speed, float alpha) { super(x, y); this.sprite = sprite; this.alpha = alpha; sprite.setAlpha(alpha); sprite.setPosition(x, y); this.minAmount = minAmount; this.maxAmount = maxAmount; this.subAmount = subAmount; this.speed = speed; }
public FadingSprite(Sprite sprite, float x, float y, float minAmount, float maxAmount, float subAmount, float speed) { super(x, y); this.sprite = sprite; alpha = 1f; sprite.setPosition(x, y); sprite.setAlpha(alpha); this.minAmount = minAmount; this.maxAmount = maxAmount; this.subAmount = subAmount; this.speed = speed; }
Sprite sprite = new Sprite( yourTexture ); Sprite otherSprite = new Sprite( yourOtherTexture ); sprite.setAlpha(0.1f); // 0f is full transparent when 1f is full visible ... batch.begin(); sprite.draw( batch ); //this one will be almost transparent otherSprite.draw( batch ); //this one will be normal batch.end();
public void update() { if (Timer.getTimeElapsed() - lastTime > speed) { if (loop) { alpha -= subAmount; if (alpha <= minAmount) { alpha = minAmount; subAmount = -subAmount; } else if (alpha >= maxAmount) { alpha = maxAmount; subAmount = -subAmount; } } else { if (fadeOut) { alpha -= subAmount; if (alpha <= minAmount) { alpha = minAmount; } } else { alpha += subAmount; if (alpha >= maxAmount) { alpha = maxAmount; } } } sprite.setAlpha(alpha); lastTime = Timer.getTimeElapsed(); } }
public void drawShape(AssetManager assetManager, Camera camera, GDXShape shape, Body body, Batch batch, float alpha){ if(shape.getResource().isEmpty()){ Log.debug("GDXRenderer.drawShape", "Resource empty string, not drawing"); return; } Texture texture = null; try{ texture = assetManager.get(shape.getResource()); }catch(GdxRuntimeException e){ Log.error("GDXRenderer.drawShape", e.getMessage() + ", loading " + shape.getResource() + " manually"); texture = getTexture(shape.getResource()); } if(!shape.isRepeatable() && texture != null && body != null){ Sprite sprite = new Sprite(texture); sprite.setScale(SHAPE_SCALE); sprite.setRotation((float)Math.toDegrees(body.getAngle())); sprite.setPosition(body.getPosition().x - texture.getWidth()/2f, body.getPosition().y - texture.getHeight()/2f); if(alpha != 1f) sprite.setAlpha(alpha); sprite.draw(batch); } }