如果我必须仍然相交的对象。
我如何知道我应该将它们移动多少才能阻止它们相互接触?
我知道如何判断哪些对象是相交的(使用 java 的 intersects 方法。
我还应该提到,所有对象都在对象列表中(称为 objs 波纹管)......
public void move(Object ob){
// this rectangle surrounds the object I'll check against
// all of the other objects below
Rectangle objectToCheck = ob.getBounds();
// Cycle through all the other objects and check if they
// cross over the rectangle I created above
for(Object obj : objs){
// Creates a bounding rectangle that is used temporarily
// for each other object on the board
Rectangle otherObject= obj.getBounds();
// Check if one object crosses over another object
if(otherObject != objectToCheck && otherObject.intersects(objectToCheck)){
// they intersect! now how do i know how much to move them so
// that they no longer intersect?
}