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 8974347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:39:43+00:00 2026-06-15T18:39:43+00:00

Hello guys I hope you can help me. I try to code a game

  • 0

Hello guys I hope you can help me. I try to code a game but I fail at collision. I searched a lot and found out that the bounding box method (to create a unvisible rectangle around the sprite) is the best soulution for me. But the intersect method is not working for me. I have two bitmap sprites which collide, but in the LogCat there is no collision…

Sprite No. 1 Class

public Sprite(GameView theGameView, Bitmap bmp) {
    this.theGameView = theGameView;
    this.bmp = bmp;
    this.width = bmp.getWidth();
    this.height = bmp.getHeight();
    ySpeed = 0;
    xSpeed = 1;
}


 public Rect bounds() {         
        return (new Rect(x,y,width,height));
    }


public void onDraw(Canvas canvas) {
    canvas.drawBitmap(bmp, x, y, null);
}

Sprite No. 2 Class

public FourthSprite(GameView theGameView, Bitmap bmp) {
    this.theGameView = theGameView;
    this.bmp = bmp;
    this.width = bmp.getWidth();
    this.height = bmp.getHeight();
    ySpeed =  0;
    xSpeed = -1;
}


public Rect bounds() {
    // TODO Auto-generated method stub
    return (new Rect(x,y,width,height));
}

public void onDraw(Canvas canvas) {
         canvas.drawBitmap(bmp, x, y, null);
}

}

GameView Class

public void collision() {

   Rect r1 = theSprite.bounds();  // Sprite on left side
       Rect r4 = theSprite4.bounds(); // Sprite on right side

  if (r1.intersect(r4)){

       collision = true;
       Log.v("Log Tag", "COLLISION :D :D :D :D :D :D :D");
   }

  else       {
       collision = false;
       Log.v("Log Tag", "NO COLLISION");
  }
    }

If it helps i can also upload a video.

Edit: http://youtu.be/wYxZ7nKsmdw
I figured out, that collision is working, when one sprite does not move arround and the x,y coordinates are 0. What could be the problem?

  • 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-06-15T18:39:44+00:00Added an answer on June 15, 2026 at 6:39 pm

    According to the video and the data you’re outputting into LogCat, something seems to be wrong with the move function (which hasn’t been listed in your question).

    The left coordinates of the rectangles are changing, however the right coordinates aren’t. After some time the left coordinate of one rectangle becomes greater than right coordinate, which results in the intersects function to return false.

    On a side note, you should think about structuring your code differently, try to use inheritance instead of a lot of very similar classes.

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

Sidebar

Related Questions

Hello guys I can't provide the code but you can see it on the
Hello all I have a question I hope you guys can help me with.
Hello StackOverflow Community, I hope you guys can help me with this here: On
Hello Guys can you help me for creating a TextView in title bar so
Hello Guys! See I have been creating a code powered with ajax but it
Hello guys maybe you maybe can help . here is my problem For example
Hello guys. I think it isn't possible just using PHP, but just to be
hello guys I am trying to extract all the anchor links from aol but
hello guys i am try to print the output of two element data simultaneously
Hello guys i try to get an object global/persistent over more than one php

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.