Hello.
I have images I use as buttons for my start menu. So far I used to create GeneralPath around the image and when mouse click event happens I tested if it was clicked inside it to simulate click on image. GeneralPath has excellent method for this (implemented Shape), contains(x,y).
I’m wondering is there a similar method for Images also… Since BufferedImage dosen’t have contains() or anything similar, I deceided to write the method myself. I’ve looked at BufferedImage, and I can’t find any method that returns x and y coordinates where the image was drawn (for example for top left corner of image) and without it I can’t do it. :-
Is there a better way to do this or some method with weird name so I missed it? All I want is method that returns true if some x and y coords you provide as argument are in drawn image area. Thank you all.
Well, you know where you’ve drawn the images… in which order… and how big they are. So with the absolute coords you can easily determine if it was inside one of those images.
The easy way would be using Rectangle. Set its bounds accordingly and do a contains check.
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Rectangle.html
yes I know but It would be much simpler and reusable If I could write one method that I can use for every picture… that way I wouldn’t have to change a thing each time I change the picture or something related to coords.
I see I’ll need to create a Rectange for evey picture specially, no reusable way I guess… I’m kind of dissapointed in Java with lack ot this stuff.
Believe me, its enough what Java provides us
Abstract your classes to be a Sprite instances and you can have anything you want within the game object.
Uhm… well, the things is… you can draw an image several times. So its logical that java doesnt provide something like this. I mean… how should that look like? Each image dragging around a list of locations it was been drawn to? Dont you think that would be a major pain in the rear?
If you want to have something like a button… just make a class like that. Or use a sprite class or something like that.