@Override public void onDraw(Canvas canvas) { if (fillTexture != null) { int size = TeraMath.floorToInt(canvas.size().x * getValue()); int barWidth = fillTexture.getWidth(); int offset = 0; if (time != null && animate) { offset = TeraMath.floorToInt(time.getRealTimeInMs() / 10) % barWidth; } int drawnWidth = 0; // Draw Offset if (offset != 0) { int drawWidth = Math.min(size, offset); canvas.drawTextureRaw( fillTexture, Rect2i.createFromMinAndSize(0, 0, drawWidth, canvas.size().y), ScaleMode.STRETCH, barWidth - offset, 0, drawWidth, canvas.size().y); drawnWidth += drawWidth; } // Draw Remainder while (drawnWidth < size) { int drawWidth = Math.min(size - drawnWidth, barWidth); canvas.drawTextureRaw( fillTexture, Rect2i.createFromMinAndSize(drawnWidth, 0, drawWidth, canvas.size().y), ScaleMode.STRETCH, 0, 0, drawWidth, canvas.size().y); drawnWidth += drawWidth; } } }