package com.backfire.Animation;

import android.graphics.Bitmap;

import com.backfire.doudizhu.common.BitmapManager;
import com.backfire.doudizhu.common.DdzApplication;
import com.backfire.graphics.PCanvas;

/**
 * @Title: AnimationToast.java
 * @Package com.backfire.Animation
 * @Description: TODO(用一句话描述该文件做什么)
 * @author Potter
 * @date 2013-12-5 上午11:21:17
 * @version V2.0
 */
public class AnimationToast extends Animation {

	private int[] textures = new int[1];
	private int index = 0;

	private float statetime = 0.0f;
	private float endTime = 0;
	private int x = 0;
	private int y = 0;
	private int width = 0;
	private int hight = 0;

	public AnimationToast(int resID, int w, int h, int x, int y, float endTime) {
		textures[0] = resID;

		this.width = w;
		this.hight = h;
		this.x = x;
		this.y = y;

		this.endTime = endTime;
	}

	@Override
	public void exec(PCanvas canvas, long sleep) {
		super.exec(canvas, sleep);
		statetime += this.sleep;
		index = getCurrentBitmap(statetime, textures);
		BitmapManager bpool = DdzApplication.getApplication().getBmpPool();
		Bitmap texture = bpool.getBitmap(textures[index], width, hight);
		if (null != texture) {
			canvas.drawBitmap(texture, x, y, null);
		}
		if (statetime >= endTime) {
			index = 0;
			this.deleteFlag = true;
		}
	}

	@Override
	public void unload() {
		textures[0] = 0;
		index = 0;
		x = 0;
		y = 0;
		width = 0;
		hight = 0;
		statetime = 0.0f;
		endTime = 0;
	}

	@Override
	public void overstatue() {
		this.deleteFlag = true;
	}

}
