So what I'm doing is trying to make an object hover in the air. It is meant to move up and down around the same area. I want the object move in one direction till the counter hits 20, then move it the other direction for another 20 counts. And continue to do this for the duration of the game(level).
Here's my code. I've tried changing some lines up, like not doing the -40 at the end, and resetting the counter to 0, but once my object changes direction it doesn't change back.
Thanks!
public void Ball() { if(counter<20) { counter++; setLocation(getX(),getY()+1); } else if(counter>20) { counter++; setLocation(getX(),getY()-1); } else if(counter==40) { counter-=40; counter++; } }