2 pictures in one class
in
Programming Questions
•
10 months ago
Hey guys,
I have another problem with processing.
I have two objects, which appear on the screen and which disappear when I click on them. These two objects are one picture, but I want one object with one picture and the other object with another pictures. This doesn't seem to work, so I wanted to ask you guys, what you would do.
This is my code so far. Please help me!
FIRST PAGE:
Button knopf;
Button knopf2;
int showklick = 0;
void setup () {
size (400, 400);
knopf = new Button ( random (0, 390), random (0, 390),140,100);
knopf2 = new Button ( random (0, 390), random (0, 390),70, 50);
}
void draw () {
background (0);
knopf.zeichne ();
knopf2.zeichne ();
}
void mousePressed () {
if(knopf.klick() || knopf2.klick()){
showklick = showklick+1;
println (showklick);
}
}
SECOND "CLASS" PAGE:
class Button {
float xPos;
float yPos;
float yPosneu;
int weite;
int hoehe;
PImage img;
Button (float xPos, float yPos, int weite, int hoehe){
this.xPos = xPos;
this.yPos = yPos;
this.weite = weite;
this.hoehe = hoehe;
img = loadImage("moorhuhn.png");
}
void zeichne () {
yPos = yPosneu + 30*sin(radians(xPos));
image (img, xPos++, yPos, weite, hoehe);
if (xPos > width)
{
xPos = 0;
}
}
boolean darueber () {
if (mouseX > xPos
&&mouseX < xPos+weite
&&mouseY > yPos
&&mouseY < yPos+hoehe)
{
return true;
}
else
{
return false;
}
}
boolean klick () {
if (darueber () && mousePressed)
{
xPos = random (0, 390);
yPosneu = random (0, 390);
return true;
}
else
{
return false;
}
}
}
Thanks for your help.
1