We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am currently trying to make a few buttons using images that ofcourse change when you press the button. I am using the code from here: http://processingjs.org/learning/topic/imagebutton/ but I cannot whatever I do, find out how to make more than one button appear at the same time. there is also the problem that the button activates with a press, not a release. which is a problem because I can press on a side of the screen, drag my mouse over the button and it then activates.
Answers
you need to make an array:
and then in draw() for loop over those
you can replace if(over && mousePressed) { by if(over && mouseReleased) { afaik
I keep getting the error "the type of the expression must be an array type but it resolved to (nameoftheprogram).imageButtons.
I am very unsure of how to make an array since I am very new at programming still. :P
https://processing.org/reference/Array.html
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
post entire code
in every spot where you had button. e.g.
we want now
button[...].update();
button[....].display();
I did some tinkering with the things iv'e read here and seen on youtube and from looking at codes, that I figured out a fairly simple way of creating buttons. I am sure there are easier ways, but anyways. I will post my code here if anyone is interested :)
this was to test if it worked, and I successfully made it able to track the mouse hovering over button and the release of the button aswell as pressing it. (this is surely not the optimal way, but I am super new at programming)
EDIT seems like you can still hold down the button, drag mouse away and release, and the button still counts as pressed.
some minor changes ...
1.
this line can be in setup()
PImage p0, p1, p2, p3;
local vars are always better than global vars
done.
2.
in lines 41 to 44 you forgot to use the arrays
buttonX1
etc. etc.that will come back and haunt you when you have more buttons than one
fixed
3.
I used ctrl-t to auto-format in processing (indents)
4.
you dropped the whole class / object thing... which is fine since you are a beginner... later you should really come back here and master the whole class / object thing...
;-)
The only change is that it flickers to it's pressed image (brush2.png) and I can still release mouse anywhere to change the value of test2
true
I don't have the images
in mouseReleased() you want to check if we are still inside the same button
is (brush2.png) supposed to be shown during mouse button is held down?
then you could set a marker in mousePressed() and eval it in draw() with if
Thank you so much Chrisir, that helped alot :) and didn't know abot CTRL - T, that is useful and saves time :D
;-)