We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Vector2; public class MyGame extends ApplicationAdapter { SpriteBatch batch; Texture ballTexture; Vector2 ballPosition; Vector2 ballVelocity; @Override public void create() { batch = new SpriteBatch(); ballTexture = new Texture("ball.png"); ballPosition = new Vector2(100, 100); ballVelocity = new Vector2(3, 3); } @Override public void render() { Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); updateBallPosition(); batch.begin(); batch.draw(ballTexture, ballPosition.x, ballPosition.y); batch.end(); } private void updateBallPosition() { ballPosition.x += ballVelocity.x; ballPosition.y += ballVelocity.y; if (ballPosition.x < 0 || ballPosition.x > Gdx.graphics.getWidth() - ballTexture.getWidth()) { ballVelocity.x *= -1; } if (ballPosition.y < 0 || ballPosition.y > Gdx.graphics.getHeight() - ballTexture.getHeight()) { ballVelocity.y *= -1; } } @Override public void dispose() { batch.dispose(); ballTexture.dispose(); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: