Hey, I want my character to attack into the direction of a mouse click and momentarily change his sprite to the corresponding attacking sprite (i named them upHit.png, downHit.png etc.). The pasted code is working, but only for 2 opposing directions at the time, in this case up and down. I think I understand why, which would mean this approach would probably not work, to begin with. I had another idea of dissecting the area around the player into 4 45 degree angles and working with that, not quite sure how that would be implemented though. Maybe the current approach would work but with a few more conditions?
private void attackAnimation(){
MouseInfo mouse = Greenfoot.getMouseInfo();
if(Greenfoot.mouseClicked(getWorld())){
if(getX() < mouse.getX()){
setImage("rightHit.png");
}
else setImage("leftHit.png");
}
if(Greenfoot.mouseClicked(getWorld())){
if(getY() < mouse.getY()){
setImage("downHit.png");
}
else setImage("upHit.png");
}
}
