Advertisement
Guest User

ScissorStack not working as intended

a guest
Apr 5th, 2014
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. public class ClipTest extends Group {
  2.     class ClipImage extends Image {
  3.         public ClipImage(Texture texture) {
  4.             super(texture);
  5.         }
  6.  
  7.         @Override
  8.         public void draw(SpriteBatch batch, float parentAlpha) {
  9.             Rectangle scissors = new Rectangle();
  10.             Rectangle clipBounds = new Rectangle(getX(), getY(), getWidth() * 0.75f, getHeight());
  11.  
  12.             ScissorStack.calculateScissors(
  13.                     getStage().getCamera(),
  14.                     getStage().getGutterWidth(),
  15.                     getStage().getGutterHeight(),
  16.                     getStage().getCamera().viewportWidth,
  17.                     getStage().getCamera().viewportHeight,
  18.                     batch.getTransformMatrix(),
  19.                     clipBounds, scissors);
  20.  
  21.             if (ScissorStack.pushScissors(scissors)) {
  22.                 super.draw(batch, parentAlpha);
  23.                 ScissorStack.popScissors();
  24.             }
  25.         }
  26.     }
  27.  
  28.     Image background, foreground;
  29.  
  30.     public ClipTest() {
  31.         setSize(100, 30);
  32.  
  33.         background = new Image(G.assets.textureSolidBlack);
  34.         background.setSize(getWidth(), getHeight());
  35.         addActor(background);
  36.  
  37.         foreground = new ClipImage(G.assets.textureSolidWhite);
  38.         foreground.setSize(getWidth(), getHeight() +10);
  39.         foreground.getColor().a = 0.75f;
  40.  
  41.         addActor(foreground);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement