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

  • Home
  • SEARCH
  • 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 4112394
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:11:24+00:00 2026-05-20T22:11:24+00:00

I think I have hit a coders block here. I am writing a game

  • 0

I think I have hit a coders block here. I am writing a game where multiples images will fall from the top of the screen and you have to catch them at the bottom. There will be an indeterminate number of images, so you don’t know how many there will be upon start time. For the life of me I CANNOT figure out the way to implement this. I understand the logic, but am having trouble trucking through Android’s classes. I tried to create my own “blossom” object, but every time I try to write anything having to do with a bitmap inside of it, it freaks out. Maybe I’m just writing the class wrong, I don’t know. All of this is being performed on a SurfaceView. Is there anybody who has any ideas on how to accomplish this? Here is my code thus far:

    public class BoardView extends SurfaceView implements SurfaceHolder.Callback{
    Context mContext;


    Bitmap box = 
        (BitmapFactory.decodeResource
                (getResources(), R.drawable.box));

    Bitmap blossom = 
        (BitmapFactory.decodeResource
                (getResources(), R.drawable.blossom));

    private BoardThread thread;
    private float box_x = 140;
    private float box_y = 378;
    private float blossom_x = 0;
    private float blossom_y = 0;
    private float boxWidth = box.getWidth();
    private float boxHeight = box.getHeight();
    private float blossomWidth = blossom.getWidth();
    private float blossomHeight = blossom.getHeight();
    private Random generator = new Random();



    boolean mode = false;

    RectF boxRect = new RectF(box_x,box_y, box_x + boxWidth, box_y + boxHeight);
    //ImageView box_view;

    public BoardView(Context context){
        super(context);

        //surfaceHolder provides canvas that we draw on
        getHolder().addCallback(this);

        // controls drawings
        thread = new BoardThread(getHolder(),this);

        //draws the blossom at a random starting point
        blossom_x = generator.nextInt(300);


        //box_view = (ImageView)findViewById(R.id.box_view);
         //box_view.setVisibility(ImageView.VISIBLE);
         //TranslateAnimation anim = new TranslateAnimation(0,0,300,0);
         //anim.setDuration(500);
         //box_view.startAnimation(anim);

        //intercepts touch events
        setFocusable(true);

    }


    @Override

    public void onDraw(Canvas canvas){
        canvas.drawColor(Color.WHITE);  


        //draw box and set start location
        canvas.drawBitmap(box, box_x - (boxWidth/2), 
                box_y - (boxHeight/2), null);

            canvas.drawBitmap(blossom, blossom_x,
                blossom_y = blossom_y+3 , null);

        //collision detection, currently not working after 
            //implementing random draw
            if(blossom_y + blossomHeight == box_y)
        {
            canvas.drawBitmap(blossom, 40,100, null);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event){

        if(event.getAction() == MotionEvent.ACTION_DOWN){
            if(boxRect.contains(event.getX(),event.getY())){
                mode = true;
            }
        }

        if(event.getAction() == MotionEvent.ACTION_MOVE) {
            if(boxRect.contains(event.getX(),event.getY())){
                mode = true;
            }
            if(mode == true){
                box_x = (int)event.getX();
                boxRect.set(box_x,box_y, box_x + boxWidth, box_y + boxHeight);
            }

        }

        if(event.getAction() == MotionEvent.ACTION_UP){
            mode = false;
        }

        invalidate();

        return true;
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, 
            int format, int width, int height ){

}

    @Override
    public void surfaceCreated(SurfaceHolder holder){
        thread.startRunning(true);
        thread.start();
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder){
        thread.startRunning(false);
        thread.stop();
    }
}

I am currently using a bitmap to draw the falling flower. I started making a class for the flower object instead, which so far looks like this

    public class Blossom{
    private Bitmap blossom;

    public Blossom()
    {
        Bitmap blossom = 
            (BitmapFactory.decodeResource
                    (getResources(), R.drawable.blossom));
    }
    public void setImage(Bitmap bitmap)
    {
        //sets the image for the blossom;
        Bitmap blossom = bitmap;
    }
}

It keeps giving me an error saying getResources is undefined for the Blossom class. When I try to write a method called setImage, and do the setting of the Image in the BoardView class, it won’t let me at all 🙁 It looked something like this

    public class Blossom{
    private Bitmap blossom;

    public void setImage(Bitmap bitmap)
    {
        //sets the image for the blossom;
        Bitmap blossom = bitmap;
    }
}

Can anybody see what is going wrong here?

  • 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-20T22:11:25+00:00Added an answer on May 20, 2026 at 10:11 pm

    Since your class extends SurfaceView, you should be doing getContext().getResources()

    Edit – if you want to use getResources in your other class, then you need to pass in a Context as well. You might instead just pass in your Bitmap instead of trying to fetch it from that data class.

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

Sidebar

Related Questions

I have set up a Django application that uses images. I think I have
I have copied this question here from spring forum . I have a parent
I have to build a program that will allow me to track from a
I think I've hit that paralysis by analysis state. I have an MVC app,
I think I have a solution to this, but is there a better way,
This follows a couple of other questions (but I think I have refined my
Over the years, I think I have seen and tried every conceivable way of
That's the question. Give only one reason you think why have OODB failed or
I'm used to doing Java programming, where you never really have to think about
I think it important to have an undo method ala gmail when destroying records

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.