谢谢,看看这个代码,它可能对您有用旋转的位图图像.. 这里我有一个采取了观赏鱼的例子,它应该移动从左至右翻转,并继续从从右向左移动,反之亦然.. 这里是
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
从崩溃发布堆栈跟踪。 –