I developed a puzzle game. In my game, I have several custom views that are nested inside FrameLayout, like layers. Each view displays a bitmap. The largest raster map is the game board, and it occupies about 2/3 of the screen. There is also a background image under FrameLayout.
When the user touches the screen, simple animations of the view are performed with this kind of game panel - they can be rotated or turned over.
Everything works fine on small screens, but users report performance issues on the Galaxy Tab - there is a noticeable lag before the animation starts, and the animation itself is not smooth. (The size of the bitmap in the game board on these screens is about 600 * 600 pixels)
Here is my layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rootFrame" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:id="@+id/backgroundImageLayer" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/background" android:scaleType="fitXY"/> <FrameLayout android:id="@+id/gameFrame" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <com.mygame.BoardView android:id="@+id/boardLayer" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <com.mygame.SomeObjectView android:id="@+id/someObjectLayer" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <com.mygame.SomeOtherObjectView android:id="@+id/someOtherObjectLayer" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </FrameLayout> </FrameLayout>
And here is my BoardView class.
public class BoardView extends View { Bitmap b; int x; int y; public BoardView(Context context, AttributeSet attrs) { super(context, attrs);
And the snippet where I am doing the animation is pretty simple:
AnimationRotate anim1=new AnimationRotate(startAngle,endAngle,centerX,centerY); anim1.setDuration(500); anim1.setInterpolator(newDecelerateInterpolator()); startAnimation(anim1);
So what causes delays in view animation and how can I fix it? Is my approach right or maybe I should use SurfaceView or frame animation or something else?
source share