This site requires JavaScript, please enable it in your browser!
Greenfoot back
Zamoht
Zamoht wrote ...

2013/10/8

Graphics2D

Zamoht Zamoht

2013/10/8

#
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);
    }
Zamoht Zamoht

2013/10/8

#
Oh never mind.. Just changed the first line to the following: GreenfootImage temp = new GreenfootImage(texture.getWidth(), texture.getHeight()); Before: http://i.imgur.com/GjJ2uOb.jpg After: http://i.imgur.com/wfOMDfJ.jpg I hate when I make mistakes like that.
You need to login to post a reply.