Reputation: 2224
I am using canvas.drawBitmap(Bitmap,src,dst,null) for animation. I am using 1 tiled images for animation, each tiled image containing more then 100 image for making animation. I have put onCLickListner to start animation. how can I have an instant responce for animations on onClick?
I have used logic for animation as per following link. http://warriormill.com/2009/10/adroid-game-development-part-1-gameloop-sprites/
@Override
public void draw(Canvas canvas) {
try
{
FrameInfo frameinfo= animations.get(currentAnimation).sequence.get(currentFrame);
Rect rclip = frameinfo.rect;
Rect dest = new Rect(this.getXpos(), getYpos(), getXpos() + (rclip.right - rclip.left),
getYpos() + (rclip.bottom - rclip.top));
if(cf!=null)
{
//color filter code here
}
canvas.drawBitmap(tileSheet, rclip, dest, null);
update(); //after drawing update the frame counter
}
catch (Exception e)
{
Log.e("ERROR", "ERROR IN SPRITE TILE CODE:"+e.toString()+e.getStackTrace().toString());
}
}
Upvotes: 4
Views: 863
Reputation: 1331
Resource loading takes significant time (they are compressed inside your APK), so much that you must pre-load these, and not load them just-in-time.
The draw()
method is the last place to be doing any just-in-time resource handling.
You should also be doing that in the background, to avoid ANR issues. An AsyncTask
implementation works just great!
You will also need to be very careful about matching DPI, or drawBitmap()
will scale your bitmaps, which will degrade your frame rate noticeably.
If you have the skill, use OpenGL with 2D texture mapping.
Upvotes: 1