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

2016/7/14

Transparent part of an PNG sound not be able to be clicked

31oli31 31oli31

2016/7/14

#
Hello, I'm a student from Germany. I have started to program a view months ago. So and hier is the question: I have saved a picture from a circle as a PNG file. Now I want that a message-box get opened if I click on the circle. Until this point I didn't have any problems. But here is my problem: if I click on the transparent part of the picture the message-box get also opened and I don't want that the message-box get opened. I know that the message-box get opened because the mouse inside the frame of the picture, but is there any was to solve this Problem? Sorry for my bad English. Thank you for your answers ....
Super_Hippo Super_Hippo

2016/7/14

#
Du könntest, statt etwas wie 'Greenfoot.mousePressed(this)' zu nutzen, den Abstand der Maus während des Klicks mit der Mitte des Objekts (=Mitte des Kreises) bestimmen und wenn er geringer als der Radius ist, dann soll es als Klick auf den Kreis gelten. Oder du überprüfst, ob der Pixel des Bildes, auf dem die Maus während des Klicks ist, nicht transparent ist. Falls du wirklich ein Student bist, ist dein Englisch echt eine Katastrophe. Ich habe dir daher lieber gleich auf Deutsch geantwortet. ;)
valdes valdes

2016/7/14

#
You can use something like this (inside Circle actor class)
if (Greenfoot.mouseClicked(this)) {
            MouseInfo info = Greenfoot.getMouseInfo();
            int posX = info.getX();
            int posY = info.getY();
to know where the mouse is. From there you can calculate if (posX, posY) is inside the circle using math Remember that getX() and getY() of an actor gives you the center coordinate. or maybe checking the color of that pixel. getImage().getColorAt(posX,posY)
31oli31 31oli31

2016/7/15

#
Thank you for your answers , you have helped me a lot . But I still have a question. In this Picture there are 2 Actors , the green square and the black triangle . Around the triangle you can see the context of the triangle. And here the same question arises . When I click the triangle in the transparent area the programm will open a message box of the triangle and not from the square. Here I can not verify how far the mouse is away from the center of the circle . https://www.dropbox.com/s/hrzhfcwdju5xhwt/Greenfootproblem.png?dl=0
danpost danpost

2016/7/15

#
Both the circle and the triangle/rectangle issues can be resolved using math. The circle issue is a 'length of an hypotenuse' problem (distance between two points) while the triangle/rectangle issue is a basic ratio problem (the percent distance of the mouse click from the center of the actor image to the left or right edge of the actor image compared to the percentage distance of the mouse click from the top edge of the actor image to the bottom edge). Both can also be resolved by checking for the color of the image at the location of the mouse click. If the color is not transparent then the click was on the represented object.
You need to login to post a reply.