Developing a little game

Developing a little game

I am trying to make a game.

I am trying to make a game.

I have a mainActivity which is called BridgeScene here and I create a class for the ennemy

In the mainActivity, I have two ImageView and some button!

In my class, I have an ennemy (represented by a Rectangle) and I use Canvas to draw a Rectangle. What I need to is to draw this Rectangle on my BridgeScene Activity. How can I do that?

I cannot set the contentview twice because it is already set in the activity as setContentView(R.layout.activity_bridge_scene);

So how can I draw my rectangle from my class ennemy in my BridgeScene activity?

My activity:

public class BridgeScene extends AppCompatActivity {

private static final  int[] ALL_DRAWABLE_RES_EAGLE = new int[]{
        R.drawable.stickmanreturnkick0,
        R.drawable.stickmanreturnkick1,
};

private Ennemy1 ennemy1;

private Handler handler = new Handler();
private final static long Interval = 30;

private Runnable updateImageTask;
private int currentDrawableResIndex;

private static long IMAGE_UPDATE_DELAY_MILLIS = 30;

private ImageView imvStickman;
private ImageView imvJump;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bridge_scene);

    ennemy1 = new Ennemy1(this);
    setContentView(ennemy1);

    updateImageTask = new UpdateImageTask();

    imvJump = (ImageView) findViewById(R.id.imvJump);

    imvStickman = (ImageView) findViewById(R.id.imvStickman);
    imvEnnemi = (ImageView) findViewById(R.id.imvEnnemi);

    imvJump.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
           //code//
        }
    });
}

}

My class:

public class Ennemy1 extends View{
    public  Bitmap rec;
    public  int recX;
    public  int recY;

public int canvasWidth;
public int canvasHeight;

public Ennemy1(Context context){
    super(context);
    rec = BitmapFactory.decodeResource(getResources(), R.drawable.enem1);
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawBitmap(rec, 100, 100, null);
    canvasWidth = canvas.getWidth();
    canvasHeight = canvas.getHeight();
}

}


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Java Fundamentals: Learn Java for absolute beginners |Simpliv

Java Fundamentals: Learn Java for absolute beginners

Java Essentials : Learn Core Java From Basic to Advance

Learn Java Programming Using Practical Assignments. Start Building Back-end Web Applications Robust Test Automation Frameworks By End Of The Course. Learn More!

Android App Development Company in UAE

Have a plan to build an robust Android App Development with multiple features? We at Data EximIT is one of the best **[Android App Development Company in UAE](https://www.dataeximit.com/android-application-development/ "Android App Development...