Collision methods anyone.

Hi, I am making a 2d platform game. Ok I use a tile class to display each individual tile for the background.

below is how I display each tile in turn every frame

Graphics g2 = g.create(x,y,_width,_height);

g2.drawImage(_tileImage,-tileX,-tileY,null);

updateBound(x,y);

note the updateBound(x,y) actually updates the bounding box of that particular background tile.

The main character controlled by the player also has a bounding box.

ok here is where I test to see if there is a collision between a particular background tile and the main character.

however I cna't detect and collsions anyone know why.

publicboolean collisionTest(MainCharacter _character,int tileNum){

return _character.getCharacterBounds().intersects(bkCollection[tileNum].getBound());

}

anyone have any ideas. thanks

[1087 byte] By [zainuluka] at [2007-9-28 7:28:47]
# 1

have you tried a little bit of debugging, to see if the 2 rectangles DO actually intersect? (you arn't using 2 different coordinate systems are you)

another point - creating a new graphics context every time you draw a sprite is very wasteful. It is best just to share the same graphics context for all draw operations per frame.

Abusea at 2007-7-9 18:40:13 > top of Java-index,Other Topics,Java Game Development...
# 2

I am actually passing the graphics ...thing to where it is to draw the image.

for example...

here is the paint method in the character class

public void paint(Graphics2D g2d){

Graphics gChar = g2d.create((int)current_pos.x(), (int)current_pos.y(),tileWidth,tileHeight);

gChar.setColor(Color.red);

gChar.drawImage(image, -(x_array[currentXFrame]), -(y_array[currentYFrame]), null);

gChar.dispose();

}

here is were the background tiles are placed

public void paint(Graphics2D g,int x,int y){

Graphics g2 = g.create(x,y,_width+100,_height);

g2.drawImage(_tileImage,-tileX,-tileY,null);

updateBound(x,y);

}

any ideas.thanks

zainuluka at 2007-7-9 18:40:13 > top of Java-index,Other Topics,Java Game Development...
# 3

Yeah but listen to what Abuse said.

Try putting a System.out.println() statement in where you test for intersection. Then you see whether or not the bounding boxes intersected. Also maybe try not using graphics2d and those other 2d classes until you get it working with only graphics 1d. Or maybe use graphics 2d alone. afterall it is a subclass of graphics 1d.

javatypoa at 2007-7-9 18:40:13 > top of Java-index,Other Topics,Java Game Development...
# 4
I have tired what you said....and yes there seems to be collisions between two character classes but not between the character and any particular tile.
zainuluka at 2007-7-9 18:40:13 > top of Java-index,Other Topics,Java Game Development...
# 5
I have an update.........my character detects only some of a particular tiles.....for example i8f I use several of the same tile....the character will only detect one or two of those particular numbered tiles and not any of the others ...any ideas. thanks
zainuluka at 2007-7-9 18:40:13 > top of Java-index,Other Topics,Java Game Development...