Hi.
I can get the Button that is clicked with mouse.getButton(), but how do i get it when the button goes up again, so it will only go into an if() if the button is released, you know what i mean?
public void act()
{
MouseInfo m = Greenfoot.getMouseInfo();
if(m != null) checkClick(m);
}
private void checkClick(MouseInfo m)
{
if(m.getButton() == 1) //left-click
{
while(m.getButton() != 0); //This is more than likely the worst way to wait, but it's what came into my head at the time :)
//Your left-click code here
}
else if(m.getButton() == 3) //right-click
{
while(m.getButton() != 0);
//Your right-click code here
}
}import greenfoot.*;
public class Buttons extends World
{
final int btnNONE = 0, btnLEFT = 1, btnRIGHT = 3;
public Buttons()
{
super(800, 600, 1);
}
public void act()
{
MouseInfo mi = Greenfoot.getMouseInfo();
if (Greenfoot.mousePressed(null))
{
int button = mi.getButton();
if (button == btnLEFT) System.out.println("Left");
if (button == btnRIGHT) System.out.println("Right");
}
if (Greenfoot.mouseClicked(null))
{
int button = mi.getButton();
if (button == btnLEFT) System.out.println("No left");
if (button == btnRIGHT) System.out.println("No right");
}
}
}if(mouse != null && mouse.getButton() == 3 && !Greenfoot.mouseDragEnded(this))
{
item_rotation++;
if(item_rotation == 4)item_rotation = 0;
}if(mouse != null && mouse.getButton() == 3 && !Greenfoot.mouseDragEnded(this))
{
item_rotation++;
if(item_rotation == 4)item_rotation = 0;
}if (Greenfoot.mouseClicked(this) && !Greenfoot.mouseDragEnded(this) && Greenfoot.getMouseInfo().getButton() == 3)