我有一個動畫,並希望當它到達顯示區域的左側時逐漸消失。擺動動畫
AffineTransform at = new AffineTransform();
at.scale(-1, 1);
at.translate((-clip.x + (clip.x - xPositionToPixel(imgX))), clip.y - 1);
if ((clip.x - clip.width) < (at.getTranslateX() - bufImg.getWidth())) {
g2d.drawImage(bufImg, at, null);
} else {
at = new AffineTransform();
at.scale(-1, 1);
at.translate((-clip.x + (clip.x - xPositionToPixel(imgX))), clip.y - 1);
g2d.drawImage(bufImg, (int)at.getTranslateX(), clip.y - 1, (int)(bufImg.getWidth() - (xPositionToPixel(imgX) + bufImg.getWidth())), clip.height, null);
}
我從右向左繪製動畫,這就是爲什麼我縮放和翻譯每個座標的原因。 clip.x是顯示區域的開始,imgX是新的x座標。
感謝您的幫助。
我想實現我想要什麼的幾個方式,最近的是這樣的:
AffineTransform at = new AffineTransform();
at.scale(-1, 1);
at.translate((-clip.x + (clip.x - xPositionToPixel(imgX))), clip.y - 1);
if ((clip.x - clip.width) < (at.getTranslateX() - bufImg.getWidth())) {
g2d.drawImage(bufImg, at, null);
} else {
at = new AffineTransform();
at.scale(-1, 1);
at.translate((-clip.x + (clip.x - xPositionToPixel(imgX))), clip.y - 1);
g2d.drawImage(bufImg, (int)at.getTranslateX(), clip.y - 1, (int)(bufImg.getWidth() - (xPositionToPixel(imgX) + bufImg.getWidth())), clip.height, null);
}
但仍然不是一個好soluation有我只是在我的萎縮圖像的寬度,但是仍然繪製完全。
好,謝謝,我會改進的是,大多數的答案是非常有價值的。 – wotan2009 2011-04-29 08:55:17