public static boolean overlaps (Rectangle r1, Rectangle r2) { return r1.overlaps(r2); }
public static boolean overlaps (Rectangle r1, Rectangle r2) { return r1.overlaps(r2); }
/** Determines whether the given rectangles intersect and, if they do, sets the supplied {@code intersection} rectangle to the * area of overlap. * @return Whether the rectangles intersect */ static public boolean intersectRectangles (Rectangle rectangle1, Rectangle rectangle2, Rectangle intersection) { if (rectangle1.overlaps(rectangle2)) { intersection.x = Math.max(rectangle1.x, rectangle2.x); intersection.width = Math.min(rectangle1.x + rectangle1.width, rectangle2.x + rectangle2.width) - intersection.x; intersection.y = Math.max(rectangle1.y, rectangle2.y); intersection.height = Math.min(rectangle1.y + rectangle1.height, rectangle2.y + rectangle2.height) - intersection.y; return true; } return false; }
/** Determines whether the given rectangles intersect and, if they do, sets the supplied {@code intersection} rectangle to the * area of overlap. * @return Whether the rectangles intersect */ static public boolean intersectRectangles (Rectangle rectangle1, Rectangle rectangle2, Rectangle intersection) { if (rectangle1.overlaps(rectangle2)) { intersection.x = Math.max(rectangle1.x, rectangle2.x); intersection.width = Math.min(rectangle1.x + rectangle1.width, rectangle2.x + rectangle2.width) - intersection.x; intersection.y = Math.max(rectangle1.y, rectangle2.y); intersection.height = Math.min(rectangle1.y + rectangle1.height, rectangle2.y + rectangle2.height) - intersection.y; return true; } return false; }
private boolean isCulled () { // we start by setting the stage coordinates to this // actors coordinates which are relative to its parent // Group. float stageX = getX(); float stageY = getY(); // now we go up the hierarchy and add all the parents' // coordinates to this actors coordinates. Note that // this assumes that neither this actor nor any of its // parents are rotated or scaled! Actor parent = this.getParent(); while (parent != null) { stageX += parent.getX(); stageY += parent.getY(); parent = parent.getParent(); } // now we check if the rectangle of this actor in screen // coordinates is in the rectangle spanned by the camera's // view. This assumes that the camera has no zoom and is // not rotated! actorRect.set(stageX, stageY, getWidth(), getHeight()); camRect.set(camera.position.x - camera.viewportWidth / 2.0f, camera.position.y - camera.viewportHeight / 2.0f, camera.viewportWidth, camera.viewportHeight); visible = camRect.overlaps(actorRect); return !visible; } }
if (viewBounds.contains(imageBounds) || viewBounds.overlaps(imageBounds)) { final float u1 = region.getU(); final float v1 = region.getV2();
if (viewBounds.contains(imageBounds) || viewBounds.overlaps(imageBounds)) { final float u1 = region.getU(); final float v1 = region.getV2();
while(iter2.hasNext()) { Rectangle bullet = iter2.next(); bullet.x -= 200 * Gdx.graphics.getDeltaTime(); if(bullet.x + 48 < 0) iter2.remove(); iter = meteorites.iterator(); while(iter.hasNext()) { if(bullet.overlaps(iter.next())) { iter2.remove(); iter.remove(); } } }
for (Rectangle spacebarRectangle : spacebar.getSpacebarRectangles()) { // section of code if (spacebarRectangle.overlaps(dino.getDinoRectangle())) { spacebarSound.play(); break; } }
dino.setOverlapping(false); for (Rectangle spacebarRectangle : spacebar.getSpacebarRectangles()) { // section of code if (!dino.isOverlapping() && spacebarRectangle.overlaps(dino.getDinoRectangle())) { dino.setOverlapping(true); spacebarSound.play(); } }
public static boolean overlaps (Rectangle r1, Rectangle r2) { return r1.overlaps(r2); }
if(Gdx.input.isKeyPressed(Keys.D){ float requestedX, requestedY; //calculate the requested coordinates Rectangle newPlayerPositionRectangle = new Rectangle(requestedX, requestedY, player.getWidth(), player.getHeight()); if (newPlayerPositionRectangle.overlaps(map) { //move the player } else { //move the player only to the edge of the map and stop there } }
/** Determines whether the given rectangles intersect and, if they do, sets the supplied {@code intersection} rectangle to the * area of overlap. * @return Whether the rectangles intersect */ static public boolean intersectRectangles (Rectangle rectangle1, Rectangle rectangle2, Rectangle intersection) { if (rectangle1.overlaps(rectangle2)) { intersection.x = Math.max(rectangle1.x, rectangle2.x); intersection.width = Math.min(rectangle1.x + rectangle1.width, rectangle2.x + rectangle2.width) - intersection.x; intersection.y = Math.max(rectangle1.y, rectangle2.y); intersection.height = Math.min(rectangle1.y + rectangle1.height, rectangle2.y + rectangle2.height) - intersection.y; return true; } return false; }
protected boolean cull() { if (!rayHandler.culling) { culled = false; } else { updateBoundingRects(); culled = chainLightBounds.width > 0 && chainLightBounds.height > 0 && !chainLightBounds.overlaps(rayHandlerBounds); } return culled; }
protected boolean cull() { if (!rayHandler.culling) { culled = false; } else { updateBoundingRects(); culled = chainLightBounds.width > 0 && chainLightBounds.height > 0 && !chainLightBounds.overlaps(rayHandlerBounds); } return culled; }
public static boolean intersect(Rectangle r1, Rectangle r2, Rectangle intersection) { if (!r1.overlaps(r2)) { return false; } float x = Math.max(r1.x, r2.x); float y = Math.max(r1.y, r2.y); float width = Math.min(r1.x + r1.width, r2.x + r2.width) - x; float height = Math.min(r1.y + r1.height, r2.y + r2.height) - y; intersection.set(x, y, width, height); return true; }
public void handleCollision(WorldObject wo) { collisionTestRect.set(desired.x, desired.y, width, height); if (wo.getBounds().overlaps(collisionTestRect)) { if (onCollide(wo)) { resetLastMove(); } else if (wo instanceof AbstractEntity) { AbstractEntity ent = (AbstractEntity) wo; if (ent.onCollide(this)) { ent.resetLastMove(); } } } }
/** * r1是否在r2内 */ public boolean isOverlaps(Actor r1, Actor r2) { rect1.set(r1.getX(), r1.getY(), r1.getWidth(), r1.getHeight()); rect2.set(r2.getX(), r2.getY(), r2.getWidth(), r2.getHeight()); return rect1.overlaps(rect2); }