K
K
krembrule20162019-05-15 15:05:08
Java
krembrule2016, 2019-05-15 15:05:08

Why is the sprite twitching?

Hello!
Wrote a function that calculates the coordinates of a sprite that moves in a circle.
Well, the formula is elementary
x = x0 + R* cos (t*a+a0)
y = y0 + R *sin (t*a+a0)
The function looks like this

public void pointDefinition(float delta){
    sprite.setPosition(Gdx.graphics.getWidth()/2+(85*(float)Math.cos(i*delta)), Gdx.graphics.getHeight()/2+(85*(float)Math.sin(i*delta)));
    i = i + 0.5;
  }

I call it in render ()
As a result, everything works, but the sprite somehow nervously twitches. Chiadnt?
Here is a video that demonstrates this bacchanalia.
https://drive.google.com/file/d/19Dfedd8dczft5PV3R...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
krembrule2016, 2019-05-15
@krembrule2016

And so, the answer was on the surface
. All that was needed was not to multiply delta by i, but to add it
As they say, "thanks to stackoverflow for my career" (c)

public void pointDefinition(float delta)
{
    sprite.setPosition((Gdx.graphics.getWidth() / 2) + (85 * (float)Math.cos(i)), (Gdx.graphics.getHeight() / 2) + (85 * (float)Math.sin(i)));
    i = i + delta;
}

W
Warlodya, 2019-05-15
@Warlodya

https://docs.oracle.com/javase/7/docs/api/java/lan...
Intuition tells me that this will help.
public void pointDefinition(float delta){
float angle = Math,ToRadians(i*delta);
sprite.setPosition(Gdx.graphics.getWidth()/2+(85*(float)Math.cos(angle)), Gdx.graphics.getHeight()/2+(85*(float)Math.sin(angle) ));
i = i + 0.5;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question