0

I need help to understand what I am doing wrong. I am setting a PNG Image as my background (canvas) and then I want to put another PNG image on top at a particular coordinate. But problem is when I set the background canvas PNG first it stays there but when the other image (on top) loads , the background canvas disappear. So obviously I am not doing something right.

Any suggestion from the android developers community would be highly appreciated.

THANKS!

HERE IS THE CODE BELOW:

StartNewGame.java:

package com.firm.armouredassault;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;

public class StartNewGame extends Activity {

    MyGame ourView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        ourView = new MyGame(this);
        setContentView(ourView);

    }




}    

Mygame.java

package com.firm.armouredassault;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;

import android.view.View;

public class MyGame extends View {

    Bitmap BTank, TShell;

    public MyGame(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        BTank = BitmapFactory.decodeResource(getResources(),     R.drawable.bluetanksm);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);

        canvas.drawBitmap(BTank, 10, 200, null);

    }

}

newgame.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/canvas"
    android:orientation="vertical" >

</LinearLayout>
4

1 回答 1

0

在画布上写一个位图,借助方法和画布作为参数将此画布传递给新画布,然后如果您在新画布上写一个新的位图,它将被写入

于 2012-05-15T11:04:41.773 回答