im currently programming on a Menu Screen for my Game. Im trying to create a Rectangle that checks if the Sprite Button is touched . Im using Abitrary World Coordinates public static int WIDTH = 1080 , HEIGHT = 720;
public void create() {
cam = new OrthoCamera();
cam.resize();
texture = new Texture("Button.png");
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
TextureRegion region = new TextureRegion(texture, 59, 52, 300,250);
sprite = new Sprite(region);
sprite.setSize(sprite.getWidth() , sprite.getHeight() )
sprite.setPosition(MyGdxGame.WIDTH / 2, MyGdxGame.HEIGHT / 2);
}
I'm using a special Orthographic Camera, if u want to see the both relevant classes klick here. (Not my Project)
public void update(OrthoCamera cam) {
if(Gdx.input.isTouched())
{
Vector3 tmp = new Vector3( Gdx.input.getX(), Gdx.input.getY(), 0);
cam.unproject(tmp);
Rectangle textureBounds = new Rectangle(0,0, 300, 250); //origin at center ?!
if(textureBounds.contains(tmp.x,tmp.y))
{
//ScreenManager.setScreen(new GameScreen());
System.out.println("Rectangle")
}
}
}
Trough testing i regognized that somehow the origin of the Rectangle Coordinate System is at the center and the width and height is set far to high. Here you can see a picture of the area where i get printet out "Rectangle" by clicking. Normaly the the origin of the Rectangle shoud be at the bottom left, right?