Collision detection of the images

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Collision detection of the images

Postby suhasmannar » Wed Jan 26, 2011 6:57 am

Hi,

I am trying to develop a game application. Here i need to check the collision detection of the images. I have drawn the images using the bitmaps.

Can some one help me how to proceed with collision detection.
suhasmannar
Developer
Developer
 
Posts: 28
Joined: Thu May 06, 2010 6:27 am
Location: Karnataka, India

Top

Re: Collision detection of the images

Postby PurpleNurple » Wed Jan 26, 2011 11:41 pm

I've also been trying to get this working today.

I'm trying to use basic bounding box collision detection using Rect.intersects(rect, rect).

Here's my method. GraphicObject is a class I defined that stores the bitmap, coordinates, speed etc.
I'm using a normal for loop to iterate through my ArrayList as I'm storing the position of each GraphicObject in
two other lists.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private void detectCollisions() {
  2.                         for (int i=0; i <_graphics.size(); i++) {
  3.                                 GraphicObject graphicA = _graphics.get(i);
  4.                                 Rect boxA = new Rect(graphicA.getCoordinates().getX(), graphicA.getCoordinates().getY(),
  5.                                 graphicA.getCoordinates().getX()+graphicA.getGraphic().getWidth(),
  6.                                 graphicA.getCoordinates().getY()+graphicA.getGraphic().getHeight());
  7.  
  8.                                 for (int j=0; j <_graphics.size(); j++) {
  9.                                         GraphicObject graphicB = _graphics.get(i);
  10.                                         Rect boxB = new Rect(graphicB.getCoordinates().getX(),
  11.                                         graphicB.getCoordinates().getY(),
  12.                                         graphicB.getCoordinates().getX()+graphicB.getGraphic().getWidth(),
  13.                                         graphicB.getCoordinates().getY()+graphicB.getGraphic().getHeight());
  14.                                        
  15.                                         if (Rect.intersects(boxA,boxB)) {
  16.                                                 _collisionA.add(i);
  17.                                                 _collisionB.add(j);    
  18.                                         }
  19.                                 }
  20.                         }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


When I run the game it run's as it did before I implemented the collision detection, it seems to have no effect. I've made sure it's being called from the main loop (obviously :P ). I'm not really sure what the problem is, theres no compile-time or run-time errors or exceptions being thrown. It just doesn't work.

Any help is greatly appreciated :)
PurpleNurple
Freshman
Freshman
 
Posts: 4
Joined: Wed Jan 26, 2011 9:32 pm

Re: Collision detection of the images

Postby PurpleNurple » Wed Jan 26, 2011 11:42 pm

Sorry found this thread by search, didnt realise it's on the wrong place, ill post elsewhere.
PurpleNurple
Freshman
Freshman
 
Posts: 4
Joined: Wed Jan 26, 2011 9:32 pm

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests