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[]{

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;

protected void onCreate(Bundle savedInstanceState) {

    ennemy1 = new Ennemy1(this);

    updateImageTask = new UpdateImageTask();

    imvJump = (ImageView) findViewById(;

    imvStickman = (ImageView) findViewById(;
    imvEnnemi = (ImageView) findViewById(;

    imvJump.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {


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){
    rec = BitmapFactory.decodeResource(getResources(), R.drawable.enem1);

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


java android

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Top Android Projects with Source Code

Android projects with source code - Work on real-time android projects. We’ll start project ideas from beginners level and later move to advance projects.

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK? OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE).

Building Dark Mode Theme in Android

Hello World, today we are going to see how we can implement a dark theme or night mode in our android application. This tutorial is going to be very simple and easy to understand. The dark theme is attractive to users and it is comfortable for low light conditions.

Top 130 Android Interview Questions - Crack Technical Interview Now!

Top Android Interview Questions & Answers from Beginner to Advanced level. Get ready to crack your next android interview with these android interview questions

Android Menu - Steps to implement Menu in Android - DataFlair

Implement Android Menu in your application - Provide functionality to your application and make it user friendly. Also, Learn its types and implementation.