Auf Thema antworten

Ach, bin ich doof!

@Marco13 Die exakte Ausgabe lautet dauerhaft :

Checking 0

Alpha is 0


Hier noch einmal richtig:

[code=Java]

/**

     * returns the if the two entitys(represented by x, y and the image) are colliding

     * @param x1

     * @param y1

     * @param img1

     * @param x2

     * @param y2

     * @param img2

     * @return

     */

    public static boolean getAreColliding(int x1, int y1, int w1, int h1, BufferedImage img1, int x2, int y2, int w2, int h2, BufferedImage img2)

    {

        BufferedImage img11 = new BufferedImage(w1, h1, img1.getType());

        BufferedImage img22 = new BufferedImage(w2, h2, img2.getType());

       

        Graphics g1 = img11.getGraphics();

        g1.drawImage(img1, w1, h1, null);

       

        Graphics g2 = img22.getGraphics();

        g2.drawImage(img2, w2, h2, null);

       

        Rectangle r1 = new Rectangle(x1, y1, w1, h1);

        Rectangle r2 = new Rectangle(x2, y2, w2, h2);

       

        //check if both rectangles intersects

        if(r1.intersects(r2))

        {

            for(int x=0; x<w1; x++)

            {

                for(int y=0; y<h1; y++)//running through pixels of img 1

                {

                    if(isOpaque(img11.getRGB(x, y)))//if pixel at x/y on img 1 isn`t transparent

                    {

                        if(isOpaque(img22.getRGB(x, y)))

                        {

                            return true;

                        }

                    }

                }

            }

        }

        return false;

    }

   

    protected static boolean isOpaque(int rgb)

    {

        int alpha = (rgb >> 24) & 0xff; 

        //red   = (rgb >> 16) & 0xff; 

        //green = (rgb >>  8) & 0xff; 

        //blue  = (rgb ) & 0xff; 

       

        if(alpha==0)

        {

          return false;

        }

        return true;

    }

[/code]


und die erstellung der Bilder


[code=Java]/**

     * returns the if the two entitys(represented by x, y and the image) are colliding

     * @param x1

     * @param y1

     * @param img1

     * @param x2

     * @param y2

     * @param img2

     * @return

     */

    public static boolean getAreColliding(int x1, int y1, int w1, int h1, BufferedImage img1, int x2, int y2, int w2, int h2, BufferedImage img2)

    {

        BufferedImage img11 = new BufferedImage(w1, h1, img1.getType());

        BufferedImage img22 = new BufferedImage(w2, h2, img2.getType());

       

        Graphics g1 = img11.getGraphics();

        g1.drawImage(img1, w1, h1, null);

       

        Graphics g2 = img22.getGraphics();

        g2.drawImage(img2, w2, h2, null);

       

        Rectangle r1 = new Rectangle(x1, y1, w1, h1);

        Rectangle r2 = new Rectangle(x2, y2, w2, h2);

       

        //check if both rectangles intersects

        if(r1.intersects(r2))

        {

            for(int x=0; x<w1; x++)

            {

                for(int y=0; y<h1; y++)//running through pixels of img 1

                {

                    if(isOpaque(img11.getRGB(x, y)))//if pixel at x/y on img 1 isn`t transparent

                    {

                        if(isOpaque(img22.getRGB(x, y)))

                        {

                            return true;

                        }

                    }

                }

            }

        }

        return false;

    }

   

    protected static boolean isOpaque(int rgb)

    {

        int alpha = (rgb >> 24) & 0xff; 

        //red   = (rgb >> 16) & 0xff; 

        //green = (rgb >>  8) & 0xff; 

        //blue  = (rgb ) & 0xff; 

       

        if(alpha==0)

        {

          return false;

        }

        return true;

    }

[/code]



Oben