사람이 마지막으로 터치 한 곳에서 개체를 표시하려고합니다. 그러나 내가하려고 할 때 그것은 틀린 장소에 나타난다. 다음과 같이 나는이 때문에 입력이 반환 좌표가 표시 좌표에 다른 사실 가정, 내 코드는 다음과 같습니다화면 좌표에 픽셀 좌표 적용
public class Core implements ApplicationListener, InputProcessor
{ //Has to be here otherwise the code formatting becomes buggy
private Mesh squareMesh;
private PerspectiveCamera camera;
private Texture texture;
private SpriteBatch spriteBatch;
Sprite sprite;
float moveX = 0;
private final Matrix4 viewMatrix = new Matrix4();
private final Matrix4 transformMatrix = new Matrix4();
@Override
public void create()
{
Gdx.input.setInputProcessor(this);
texture = new Texture(Gdx.files.internal("door.png"));
spriteBatch = new SpriteBatch();
sprite = new Sprite(texture);
sprite.setPosition(0, 0);
viewMatrix.setToOrtho2D(0, 0, 480, 320);
float x = 0;
float y = 0;
}
@Override
public void dispose()
{
}
@Override
public void pause()
{
}
@Override
public void render()
{
viewMatrix.setToOrtho2D(0, 0, 480, 320);
spriteBatch.setProjectionMatrix(viewMatrix);
spriteBatch.setTransformMatrix(transformMatrix);
spriteBatch.begin();
spriteBatch.disableBlending();
spriteBatch.setColor(Color.WHITE);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
//spriteBatch.draw(texture, 0, 0, 1, 1, 0, 0, texture.getWidth(),
// texture.getHeight(), false, false);
sprite.draw(spriteBatch);
spriteBatch.end();
update();
}
@Override
public void resize(int width, int height)
{
float aspectRatio = (float) width/(float) height;
camera = new PerspectiveCamera(67, 2f * aspectRatio, 2f);
}
@Override
public void resume()
{
}
public void update()
{
float delta = Gdx.graphics.getDeltaTime();
if(Gdx.input.isTouched())
{
Vector3 worldCoordinates = new Vector3(sprite.getX(), sprite.getY(), 0);
camera.unproject(worldCoordinates);
sprite.setPosition(Gdx.input.getX(), Gdx.input.getY());
float moveX = 0;
float moveY = 0;
}
}
나는 simplicty의 위해이 코드를 잘립니다. http://www.youtube.com/watch?v=m89LpwMkneI
정답이어야합니다. – HAL9000
허용 된 솔루션을 시도했지만 화면 해상도가 변경되면 정말 번거로워집니다. 필요한 모든 계산을 다시 작성하지 않으려면이 방법을 사용하십시오. – MxyL
허용 된 답변을 변경했습니다. 첫 번째 답변을 수락하면 게시되었습니다. – Derek