So this is my code, the problem lies in the timer, I get an error saying that timesClicked
is accessed from within inner class, therefore needs to be declared final
.
However, if I declare it final
, I won't be able to change it. So what do I do?
public static void displayItem(Player Dawid, Item item, int timesClicked, Sprite itemSprite){
if (Gdx.input.justTouched()) {
camera.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
if (Assets.healthPotionSPR.getBoundingRectangle().contains(touchPoint.x, touchPoint.y)) {
if (timesClicked == 1){
Shop.checkRequirement(item.getBuyPrice(), Dawid, item);
Dawid.setGold(Dawid.getGold() - HealthPotion.buyPrice);
item.setStock(item.getStock()+1);
topText = "Kupiłeś eliksir zdrowia!";
}
Assets.sellText = item.getSellPrice() + "g";
Assets.buyText = item.getBuyPrice() + "g";
timesClicked++;
timer.schedule(new TimerTask() {
@Override
public void run() {
timesClicked = 0;
}
}, 500);
}
}
}
I want to create this method, and I need to be able to provide a static int that would be eddited depending on amounts of clicks and time between each click.
EDIT
ok I got it, so there's a public static int timesClicked, then the method goes :
public static void displayItem(Player Dawid, Item item, int timesClicked, Sprite itemSprite){
if (Gdx.input.justTouched()) {
camera.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
if (itemSprite.getBoundingRectangle().contains(touchPoint.x, touchPoint.y)) {
if (timesClicked == 1){
Shop.checkRequirement(item.getBuyPrice(), Dawid, item);
}
Assets.sellText = item.getSellPrice() + "g";
Assets.buyText = item.getBuyPrice() + "g";
spriteClicked++;
timesClicked = spriteClicked;
timer.schedule(new TimerTask() {
@Override
public void run() {
spriteClicked = 0;
}
}, 500);
}
}
}