Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7526445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:49:57+00:00 2026-05-30T03:49:57+00:00

I’m a beginner at Android Development. I’ve created a game. One Bitmap (1) is

  • 0

I’m a beginner at Android Development.

I’ve created a game. One Bitmap (1) is controllable, the other bitmap (2) acts on collision with the first. Works fine. Question ; How would I create multiple instances of (2) that would, to start with, all respond to a collision with (1) in the same way.

What I’ve built so far;

In the MainGamePanel, I create the two Bitmaps :

  basket = new basket(BitmapFactory.decodeResource(getResources(), R.drawable.basket01), 50, 50);
  apple = new apple(BitmapFactory.decodeResource(getResources(), R.drawable.apple_red01));

The MainThread performs update and draws the canvas on the panel

In the update (in MainGamePanel), I check for collisions between (1) and (2), checking the coordinates.

If collision detected, I set coordinates on apple (2), it becomes ‘slotted’.

Then, if apple (2) is slotted AND touched, I move it to a random position on the screen and set the boolean slotted to false.

… this is where I’m stuck, 2 questions (should I split them up here on SO?)

  1. How would I create multiple instances of the bitmap (2)?
  2. How would I get the X and Y max values of the canvas, or view that is not created within the class itself?

Thanks!

Current Code-snippets for the bitmap (2) “apple” :

     public void draw(Canvas canvas) {
  canvas.drawBitmap(bitmap, X - width/2, Y - height/2, null);
 }

With regards to question two (review random generator, I need to set max values);

    if (slotted){
     if (eventX >= (X - width/ 2) && (eventX <= (X + width/2))) {
           if (eventY >= (Y - height/ 2) && (eventY <= (Y + height/ 2))) {
    // basket touch
    Random Rnd = new Random();

    float nX=Rnd.nextInt(HOWTOMAXOFVIEWORCANVAS);
    float nY=Rnd.nextInt(HOWTOMAXOFVIEWORCANVAS)+80; 

// the +80 is to prevent the apple from returning in the 'slotted' area (the basket can't get there ;)

    setX(nX);
    setY(nY);
    slotted = false;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:49:58+00:00Added an answer on May 30, 2026 at 3:49 am

    A very simple way would be to create a list of apples instead of separate apple instances:

    ArrayList<apple> appleList = new ArrayList<apple>();
    int nApples = 5;
    for (int i=0; i<5; i++)
          appleList.add(new apple();
    

    You DO NOT WANT want to create multiple instances of a bitmap. Bitmaps can consume a large amount of memory 4 bytes per pixel. Its would be many times better to simply create the bitmap once and then just have your apple objects reference that bitmap directly.

    The max X and Y values of the canvas are determined by the dimensions of the View you are drawing to. Once your View has been inflated and drawn you should be able to get those values from the view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.