I’m making an attempt to make an object transfer from off display screen on the correct to off display screen left and constantly generate (just like the flappy chicken pipes). How would I do that with my present code under? I’ve tried creating a category like I did with the “ball” class however I can not seem to get it to work… Any examples or assist could be appreciated. (I’m very inexperienced in recreation growth and java so please bear with me). That is my present code, I’ve the ball that jumps within the air and now need to make the spike transfer from off display screen proper to off display screen left and generate one other “spike” every time. I’ve drawn the spike which in the mean time is only a texture that doesn’t do something. Thanks.
class Ball {
public static ultimate float GRAVITY = -500;
public static ultimate float BOUNCE_DAMPENING = 0.0f;
public ultimate Vector2 place = new Vector2();
public ultimate Vector2 velocity = new Vector2();
public ultimate Vector2 acceleration = new Vector2(0, GRAVITY);
public void replace (){
float deltaTime = Gdx.graphics.getDeltaTime();
velocity.add(acceleration.x * deltaTime, acceleration.y * deltaTime);
place.add(velocity.x * deltaTime, velocity.y * deltaTime);
if (place.y <0){
place.y = -position.y * BOUNCE_DAMPENING;
velocity.y = -velocity.y * BOUNCE_DAMPENING;
}
}
}
public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
Texture background;
Texture ballTexture;
Ball ball;
Texture spikeTexture;
@Override
public void create () {
batch = new SpriteBatch();
background = new Texture("gamebackground.png");
ballTexture = new Texture("ball2.png");
ballTexture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
ball = new Ball();
spikeTexture = new Texture("spike2.png");
}
@Override
public void render () {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if (Gdx.enter.justTouched())
ball.velocity.y += 350;
ball.replace();
batch.start();
float scaleFactor = 2.0f;
batch.draw(background, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
batch.draw(ballTexture, ball.place.x, ball.place.y, ballTexture.getWidth() * scaleFactor, ballTexture.getHeight() * scaleFactor);
batch.draw(spikeTexture, 80,-260, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
batch.finish();
}
@Override
public void dispose () {
batch.dispose();
background.dispose();
ballTexture.dispose();
}
}