Skip to main content
added 3 characters in body
Source Link
ice1000
  • 286
  • 3
  • 19

I'm developing a simple game engine for practise purpose, and I used codes like this to do collision detection (fake code):

bool PhysicalObject.isCollideWith(rect: PhysicalObject) =>
  x + width >= rect.x && rect.y <= y + height &&
    x <= rect.x + rect.width &&
    y <= rect.y + rect.height

But this treats all objects as a circlerectangle.
What I want is to detect collision when two objects are overlapping on pixel level (I used java.awt.Graphics to draw my game objects).

What's the best way of doing that? Can I create a two-dimension array that represent each pixel and store the pointer to the game object that the corresponding pixel belongs to?

I'm developing a simple game engine for practise purpose, and I used codes like this to do collision detection (fake code):

bool PhysicalObject.isCollideWith(rect: PhysicalObject) =>
  x + width >= rect.x && rect.y <= y + height &&
    x <= rect.x + rect.width &&
    y <= rect.y + rect.height

But this treats all objects as a circle.
What I want is to detect collision when two objects are overlapping on pixel level (I used java.awt.Graphics to draw my game objects).

What's the best way of doing that? Can I create a two-dimension array that represent each pixel and store the pointer to the game object that the corresponding pixel belongs to?

I'm developing a simple game engine for practise purpose, and I used codes like this to do collision detection (fake code):

bool PhysicalObject.isCollideWith(rect: PhysicalObject) =>
  x + width >= rect.x && rect.y <= y + height &&
    x <= rect.x + rect.width &&
    y <= rect.y + rect.height

But this treats all objects as a rectangle.
What I want is to detect collision when two objects are overlapping on pixel level (I used java.awt.Graphics to draw my game objects).

What's the best way of doing that? Can I create a two-dimension array that represent each pixel and store the pointer to the game object that the corresponding pixel belongs to?

Source Link
ice1000
  • 286
  • 3
  • 19

How to implement pixel level collision detection?

I'm developing a simple game engine for practise purpose, and I used codes like this to do collision detection (fake code):

bool PhysicalObject.isCollideWith(rect: PhysicalObject) =>
  x + width >= rect.x && rect.y <= y + height &&
    x <= rect.x + rect.width &&
    y <= rect.y + rect.height

But this treats all objects as a circle.
What I want is to detect collision when two objects are overlapping on pixel level (I used java.awt.Graphics to draw my game objects).

What's the best way of doing that? Can I create a two-dimension array that represent each pixel and store the pointer to the game object that the corresponding pixel belongs to?