D
D
danila01642018-01-18 16:24:31
libgdx
danila0164, 2018-01-18 16:24:31

Why does the position of an object look exactly like this?

if(Gdx.input.isTouched()) {
Vector3 touchPos = new Vector3();
touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(touchPos);
bucket.x = touchPos.x - 64 / 2; ----------------------------- here is this line why 64/2
}
In the explanation it is written (the position of the bucket is changed so that the center is in touch/mouse coordinates.)
Please explain why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kzoper, 2018-01-18
@kzoper

I'm assuming the sprite's width/height is 64 px, given that libgdx reports the sprite's coordinates from the bottom left corner.
In order to get the center of the sprite, you need to perform this particular operation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question