我正在制作纸牌游戏,并从地图集中拍摄照片。如何用手指从手中取出任何卡并拖动(拖放)。我通过isTouched获得了两张卡片,但这不是必需的
@Override
public void create () {
touchPos1 = new Vector3();
touchPos2 = new Vector3();
batch = new SpriteBatch();
one = new Rectangle();
one.x = 640;
one.y = 20;
one.width = 64;
one.height = 92;
two = new Rectangle();
two.x = 688;
two.y = 20;
two.width = 64;
two.height = 92;
camera = new OrthographicCamera();
camera.setToOrtho(false, 1280, 720); //** w/h ratio = 1.66 **//
batch = new SpriteBatch();
cardAtlas = new TextureAtlas("carddd.pack"); //** Load circles.pack and circles.png **//
redZero = new TextureRegion(cardAtlas.findRegion("0R")); //** Load redCircle from circleAtlas **//
greenFive = new TextureRegion(cardAtlas.findRegion("5G"));
}
@Override
public void render () {
Gdx.gl.glClearColor(0, 1, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(redZero, one.x, one.y,100,141); //** draw Red circle **//
batch.draw(greenFive, two.x, two.y,100,141);
batch.end();
我在拖动中
if(Gdx.input.isTouched()){
touchPos1.set(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(touchPos1);
if(one.x+64 > touchPos1.x && touchPos1.x>one.x-64){
one.x = (int) (touchPos1.x);
one.y = (int) (touchPos1.y);
}
else if(Gdx.input.isTouched()){
touchPos2.set(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(touchPos2);
if(two.x+64 > touchPos2.x && touchPos2.x>two.x-64) {
two.x = (int) (touchPos2.x);
two.y = (int) (touchPos2.y);
}}