Use rotation transform to render tapped cards so overlays can be rotated too

This commit is contained in:
drdev
2014-05-24 05:30:12 +00:00
parent 23a9621de7
commit 3f47d54a93
2 changed files with 24 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;
import com.badlogic.gdx.utils.Clipboard;
@@ -892,6 +893,23 @@ public class Forge implements ApplicationListener {
endClip();
}
public void setRotateTransform(float originX, float originY, float rotation) {
batch.end();
float dx = adjustX(originX);
float dy = adjustY(originY, 0);
batch.getTransformMatrix().translate(dx, dy, 0);
batch.getTransformMatrix().rotate(Vector3.Z, rotation);
batch.getTransformMatrix().translate(-dx, -dy, 0);
batch.begin();
//shapeRenderer.setTransformMatrix(matrix);
}
public void clearTransform() {
batch.end();
batch.getTransformMatrix().idt();
batch.begin();
}
public void drawRotatedImage(Texture image, float x, float y, float w, float h, float originX, float originY, float rotation) {
batch.draw(image, adjustX(x), adjustY(y, h), originX - x, h - (originY - y), w, h, 1, 1, rotation, 0, 0, image.getWidth(), image.getHeight(), false, false);
}

View File

@@ -86,10 +86,13 @@ public class FCardPanel extends FDisplayObject {
Texture image = ImageCache.getImage(card);
if (tapped) {
float edgeOffset = w / 2f;
g.drawRotatedImage(image, x, y, w, h, x + edgeOffset, y + h - edgeOffset, tappedAngle);
g.setRotateTransform(x + edgeOffset, y + h - edgeOffset, tappedAngle);
}
else {
g.drawImage(image, x, y, w, h);
g.drawImage(image, x, y, w, h);
if (tapped) {
g.clearTransform();
}
}
}