java - Can I use an Image variable in a Mouse method instead of specific x- and y-values? [Might be Slick2D only] -


i've been creating app me understand java more , 1 of things coded ability change settings (resolution, music loudness, fps limit etc...) values (1280x720, 0-10, vsync). i've drawn images in photoshop , added them in class files, gave them place in code rendered on screen.

if((xpos>400 && xpos<600) && (ypos>255 && ypos<305)){     if(mouse.isbuttondown(0)){ 

this part of code matters, have manually search boundaries of images , simple math figure out coordinates need use, designed music loudness have 11 seperate images, 1 each value (0-10). there simpler way let java know "if cursor on image, this" or doomed code in seperate coordinates 11 times (and more times other settings.

please let me know if there's better way of doing this!

thanks.

p.s. can't seem find how draw drop-down menu slick2d , lwjgl. can still use standard java code draw drop-down menu or should library such swing job me?

make imageholder class can hold , draw image, , save position drawn at. instance, can have same draw(float x, float y) method of image, additionally save x , y coordinate , make them available through getx() , gety() methods.

put imageholders collection can iterate, , put code mouse detection loop iterates said collection. instance:

for (imageholder ih : imageholderlist) {     if (input.ismousepressed(input.mouse_left_button)) {         if (mousex >= ih.getx() && mousex < (ih.getx() + ih.getwidth())                 && mousey >= ih.gety() && mousey < (ih.getx() + ih.getwidth())) {             dosomething();     } } 

generally, if have duplicated code in program, there way make of go away abstraction.

edit: last question, slick2d , lwjgl high performance. opengl used draw images using gpu. swing on other hand used it's convenience building advanced guis. comes lot of neat abstractions , can make sorts of fancy things. however, considerably slower slick2d.

if need speed of slick2d, , in turn lwjgl on top of opengl, know comes @ cost. g in lwjgl stands gaming, because it's made gaming , not gui programming. can lot of functionality of swing in slick2d, tools twl , nifty-gui, have vastly less documentation , example code swing. being said, if fearless, give them try.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -