鼠标输入可以拖动和复制图片,而不仅仅是拖动

时间:2014-08-19 18:08:23

标签: java eclipse libgdx

以下是使用鼠标拖动图片时的示例 http://i.stack.imgur.com/4RQDU.jpg

这是代码。 当我在桌面应用程序上加载项目时,图片在中间完美显示,但是当我用鼠标移动它时,它会像在Windows XP中一样拖动它。

public class SlingshotSteve implements ApplicationListener{

private OrthographicCamera camera;
private SpriteBatch batch;
private Texture texture;
private Sprite sprite;


@Override
public void create() { 
    camera = new OrthographicCamera(1280, 720);     

    batch = new SpriteBatch();


    texture = new Texture(Gdx.files.internal("image.png"));
    sprite = new Sprite(texture);

    sprite = new Sprite(texture);
    sprite.setOrigin(0,0);
    sprite.setPosition(-sprite.getWidth()/2,-sprite.getHeight()/2);


}

@Override
public void dispose() {
    batch.dispose();
    texture.dispose();
}

@Override
public void render() {  
    // Make the background color Black
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    // Mouse imput        
    if(Gdx.input.isButtonPressed(Input.Buttons.LEFT)){
        sprite.setPosition(Gdx.input.getX() - sprite.getWidth()/2,
                Gdx.graphics.getHeight() - Gdx.input.getY() - sprite.getHeight()/2);
    }
    if(Gdx.input.isButtonPressed(Input.Buttons.RIGHT)){
        sprite.setPosition(Gdx.graphics.getWidth()/2 -sprite.getWidth()/2, 
                Gdx.graphics.getHeight()/2 - sprite.getHeight()/2);
    }

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    sprite.draw(batch);
    batch.end();
}

我不知道我做错了什么

0 个答案:

没有答案