I am trying to make an object ease in and out.
But when I render this it works well but I always get another object behaving directly opposite to the other.
So when the object is heading up, the "ghost" object will be directly opposite heading down. It gives a rather weird screen tearing effect. I've tried turning on vsync but that seemed to make it worse. The object is a slick2d rectangle. It also has the habit of completely disappearing for a few seconds or even permanently turning into a straight line without me every changing its dimensions. This is the update code.
@Override
public void update(GameContainer gc, StateBasedGame game, int delta) throws SlickException {
// TODO Auto-generated method stub
Input i=gc.getInput();
d=2000/delta;
if(i.isKeyDown(Input.KEY_DOWN)){
if(frames<d)
frames++;
if(frames==1)b=hele.getY();
hele.setY(Quad.easeInOut(frames, b, 720-b-50, d));//the 50 is the size of the sprite
//c+=10;
}
else if(i.isKeyDown(Input.KEY_UP)){
if(frames<d)
frames++;
if(frames==1)b=hele.getY();
hele.setY(Quad.easeInOut(frames, b, -b, d));
}
}
The ease in out formulas can be found here on github.
I have the frames var reset once the key is released elsewhere. I am trying to make the sprite behave like a helicopter. If you have any idea how to make it more helicopter like, please share your knowledge!
I seem to have found the problem, updating d with the delta every update causes the screen tear! Keeping it constant will solve the problem.
Instead of using a frame count I used a delta timer instead...
that keeps track of the time using the delta and for every place I used frames, I replaced with the elapsed time.
However, I still used the frame count to identify the first update for the delta isn't always reliable.
The full source can be found on git here: https://bitbucket.org/BallisticBlaze/helirush-game/
Hope this helps anyone.