0

I have tried to make a ellipse object in libgdx. Sorry if i can't describe properly but im a newbie in java.

My code looks like:

public class GameScreen implements Screen{ MyGame game; OrthographicCamera camera; SpriteBatch batch; ... Ellipse playBounds; public GameScreen(MyGame game) { this.game = game; camera = new OrthographicCamera(); camera.setToOrtho(false, 1080, 1920); batch = new SpriteBatch(); state = GAME_READY; touchPoint = new Vector3(); pauseBounds = new com.badlogic.gdx.math.Rectangle(1080-128,1920-128,128,128); playBounds= new Ellipse() } 

...

public void render(float delta) { Gdx.gl.glClearColor(1F, 1F, 1F, 1F); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.update(); generalupdate(); batch.setProjectionMatrix(camera.combined); batch.begin(); batch.draw(Assets.sprite_bg, 0, 0); switch (state){ case GAME_READY:{ batch.draw(Assets.sprite_startScreen, 0, 0); batch.draw(Assets.sprite_playButton,218,800,644,225); break; } 

Basically it draws background, a welcome screen and a button(with "play" on it) So here i made a touch detection.

 if (Gdx.input.justTouched()) { camera.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0)); if (state==GAME_READY); if (playBounds.contains(touchPoint.x, touchPoint.y)) { state=GAME_RUNNING; 

Drawing works fine but the problem is when i touch the button it doesnt work instead if i touch near it game starts as it should

1 Answer 1

1

Alright, ignoring the several errors in the code which I will just assume were made here instead of the actual code, I believe the problem could be that you are not setting the values in the Ellipse. By this I mean the width, height, x, and y.


An nice way to do this would be to use the constructor:

Ellipse(float x, float y, float width, float height)

instead of just :

Ellipse()


That way you can set the values right away. Refer to this website for more info in Ellipses for LibGDX.

If that doesn't solve your problem you may have to post a little more of the relevant parts of your code.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for link,i deleted ellipse coordinates ...there were some numbers but the main problem is that i dont understand where x and y are ..i mean in a rectangle x and y are coordinates for button left corner but in a ellipse where are those?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.