謝謝,看看這個代碼,它可能對您有用旋轉的位圖圖像.. 這裏我有一個採取了觀賞魚的例子,它應該移動從左至右翻轉,並繼續從從右向左移動,反之亦然.. 這裏是
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
fish = BitmapFactory.decodeResource(getResources(), R.drawable.fish);
v = new OurView(this);
公共類OurView擴展SurfaceView實現Runnable {
爲你的代碼..
Thread t = null;
SurfaceHolder holder;
boolean isitOK = false;
String Flag = "right";
Bitmap rotatedBitmap=null;
Matrix rotateRight = new Matrix();
Matrix rotateLeft = new Matrix();
Bitmap rSprite=null;
Bitmap lSprite=null;
public OurView(Context context) {
super(context);
holder = getHolder();
rotateLeft.setScale(-1, 1);
rSprite = Bitmap.createBitmap(fish, 0, 0,
fish.getWidth(), fish.getHeight(), rotateRight, true);
lSprite = Bitmap.createBitmap(fish, 0, 0,
fish.getWidth(), fish.getHeight(), rotateLeft, true);
}
@Override
public void run() {
// TODO Auto-generated method stub
while (isitOK == true) {
if (!holder.getSurface().isValid()) {
continue;
}
Canvas canvas = holder.lockCanvas();
canvas.drawBitmap(bg, 0, 0, null);
if(Flag == "right")
canvas.drawBitmap(lSprite, x, y, null);
if(Flag == "left")
canvas.drawBitmap(fish, x, y, null);
if (Flag == "right" && x <= 60) {
x++;
if (x == 60) {
Flag = "left";
// canvas.drawBitmap(rSprite, 0, fish.getWidth(), null);
canvas.drawBitmap(fish, x, y, null);
}
}
if (Flag == "left" && x >= 0) {
x--;
if (x == 0) {
Flag = "right";
canvas.drawBitmap(fish, x, y, null);
}
}
holder.unlockCanvasAndPost(canvas);
}
}
你是什麼意思的「翻轉」? –
可以說我有一個精靈向左走的動畫,我想用相同的精靈向右走,只是將它翻轉到另一個方向。希望我清除它.. – Baruch
從崩潰發佈堆棧跟蹤。 –