Is it possible to have two images and then draw them on each other so that only the intersecting parts gets drawn.
I have this code right now and it works fine as long as the texture is larger than or equal to the shape size. If the texture is smaller than the shape it looks weird. (The following is a method from a subclass of GreenfootImage).
public void drawShapedImage(GreenfootImage texture, Shape shape, int alpha) { GreenfootImage temp = new GreenfootImage(getWidth(), getHeight()); Graphics2D graphics = temp.getAwtImage().createGraphics(); Rectangle rect = shape.getBounds(); graphics.setComposite(AlphaComposite.Src); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setColor(new Color(0,0,0,alpha)); graphics.fill(shape); graphics.setComposite(AlphaComposite.SrcIn); graphics.drawImage(texture.getAwtImage(), null, 0, 0); graphics.dispose(); drawImage(temp, 0, 0); }