만든 소스는 이 게시물과 Animation만 바꾼 것이라 생각하면 됩니다. : http://pgm-progger.blogspot.kr/2011/05/android_2020.html
사용 목적이 게임이라 딱딱하게 움직이는게 아닌 눈에 재미를 줄 수 있는 애니메이션이 들어가는게 좋을 것같아 RotateAnimation을 알아 봤습니다.
(iv는 강제 위치 셋팅이 안되네요.. 절대레이아웃이 아니라면/또한 ani를 처음 만들면 hasStarted도 false고 hasEnded도 false라 쓰기 애매했습니다. 뭔 상태일까요..)
일단 bitmap에서 이동하는 애니메이션 코드를 보고 애니만 바꿔서 적용시키는 코드를 만들었습니다.
그랬더니 화면 좌표(0,0)를 중심으로 회전하더군요.. new RotateAnimation에 뒤에 4개 값을 별 짓을 다하며 바꿔도 기대하는 방향으로 바뀌지 않던데 뭘 잘못쓰고 있는 건지 모르겠습니다.
Q. bitmap RotateAnimation의 예제가 있다면 알려주십시오
Q. mat.rotate류 를 하면 왜 캔버스에서 이동을 할까요?
Q. bitmap과 RotateAnimation을 연결하는 방법은 없을까요? (ImageView도 안에 bitmap을 품고 있는데 그런 식으로 돌고 있는게 아닌가요?)
Q. new RotateAnimation(0, 360, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);에서 0˚에서 360˚로 // pivotXType, pivotYType의 정확한 의미가 뭔가요?
http://developer.android.com/intl/ko/reference/android/view/animation/RotateAnimation.html
로는 잘 이해가 가지 않습니다. 0값이면 (0,0), 1이면 view의 중심값에서, 2이면 부모의 (left,top)인가요? self는 어떻게 Width랑 Height를 알죠;
// View의 Init부분
onCreate()
cHexagonItem item = m_cHexagon.get(0); // item의 안에 m_ptPos는 비트맵의 (Left, Top) 값 입니다.
Drawable dr = res.getDrawable(R.drawable.hexagon124);
dr.setBounds(item.m_ptPos.x, item.m_ptPos.y, item.m_cRight.m_rcRect.right, item.m_cLeft.m_rcRect.bottom); // Image Scaling
// 아래 3가지 다 (0,0)으로 회전합니다
ani = new RotateAnimation(0, 360, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
//ani = new RotateAnimation(0, 360, RotateAnimation.RELATIVE_TO_SELF, item.m_ptCenter.x, RotateAnimation.RELATIVE_TO_SELF, item.m_ptCenter.y);
//ani = new RotateAnimation(0, 360, item.m_ptCenter.x, 0.5f, item.m_ptCenter.y, 0.5f);
ani.setInterpolator( new LinearInterpolator() );
ani.setRepeatCount(RotateAnimation.ABSOLUTE);
ani.setDuration(500);
cAniDraw = new cAnimateDrawable(dr, ani);
// View의 onDraw
@Override
protected void onDraw(Canvas canvas)
{
cAniDraw.draw(canvas);
}
이외 위에서 사용한
public class cProxyDrawable extends Drawable
{
private Drawable mProxy;
private boolean mMutated;
public cProxyDrawable( Drawable target )
{
mProxy = target;
}
@Override
public void draw( Canvas canvas )
{
if( mProxy != null )
mProxy.draw(canvas);
}
}
// cAnimateDrawable Class
public class cAnimateDrawable extends cProxyDrawable
{
private Animation mAnimation;
private Transformation mTransformation = new Transformation();
public cAnimateDrawable( Drawable target )
{
super(target);
}
public cAnimateDrawable( Drawable target, Animation ani )
{
super(target);
mAnimation = ani;
}
@Override
public void draw(Canvas canvas)
{
Drawable dr = GetProxy();
if( dr != null)
{
int sc = canvas.save();
Animation ani = mAnimation;
if( ani != null )
{
ani.start();
//ani.getTransformation( AnimationUtils.currentAnimationTimeMillis(), mTransformation );
canvas.concat( mTransformation.getMatrix() );
}
dr.draw(canvas);
canvas.restoreToCount(sc);
}
}
}
draw에 getTransfotmation(line : 28)만 하지 않으면 회전도 움직이지도 않습니다.
움직이는 애니메이션을 할 때 항상 등장하긴 하던데 변형하도록 하는 게 아닌가요?
ImageView에서 startAni를 했을 때 돌아가는 건 iv자체에서 애니메이션을 지원해주는 함수때문에
RotateAnimation.RELATIVE_TO_SELF가 정상 작동하는 것이라 생각하고 있습니다.
그러나 지금 하려는 건 단지 회전하라는 ani를 플레이만 시키니 self 중심인 0,0에서 하고 있다로 생각해봅니다.
그럼 여기서 내 해상도의 self인 중심에서 돌지 않는 것에 생각이 틀린 거 같습니다.
(8000자 제한때문에 메인만 썼습니다)