本文整理了Java中com.badlogic.gdx.math.Rectangle
类的一些代码示例,展示了Rectangle
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rectangle
类的具体详情如下:
包路径:com.badlogic.gdx.math.Rectangle
类名称:Rectangle
[英]Encapsulates a 2D rectangle defined by its corner point in the bottom left and its extents in x (width) and y (height).
[中]封装由左下角的角点及其在x(宽度)和y(高度)上的范围定义的二维矩形。
代码示例来源:origin: libgdx/libgdx
@Override
public void setView (OrthographicCamera camera) {
batch.setProjectionMatrix(camera.combined);
float width = camera.viewportWidth * camera.zoom;
float height = camera.viewportHeight * camera.zoom;
float w = width * Math.abs(camera.up.y) + height * Math.abs(camera.up.x);
float h = height * Math.abs(camera.up.y) + width * Math.abs(camera.up.x);
viewBounds.set(camera.position.x - w / 2, camera.position.y - h / 2, w, h);
}
代码示例来源:origin: libgdx/libgdx
/** Creates a {@link Rectangle} object with the given X and Y coordinates along with a given width and height.
*
* @param x X coordinate
* @param y Y coordinate
* @param width Width of the {@link Rectangle} to be created.
* @param height Height of the {@link Rectangle} to be created. */
public RectangleMapObject (float x, float y, float width, float height) {
super();
rectangle = new Rectangle(x, y, width, height);
}
代码示例来源:origin: libgdx/libgdx
/** @param point The coordinates vector
* @return whether the point is contained in the rectangle */
public boolean contains (Vector2 point) {
return contains(point.x, point.y);
}
代码示例来源:origin: libgdx/libgdx
/** Fits this rectangle around another rectangle while maintaining aspect ratio. This scales and centers the rectangle to the
* other rectangle (e.g. Having a camera translate and scale to show a given area)
* @param rect the other rectangle to fit this rectangle around
* @return this rectangle for chaining
* @see Scaling */
public Rectangle fitOutside (Rectangle rect) {
float ratio = getAspectRatio();
if (ratio > rect.getAspectRatio()) {
// Wider than tall
setSize(rect.height * ratio, rect.height);
} else {
// Taller than wide
setSize(rect.width, rect.width / ratio);
}
setPosition((rect.x + rect.width / 2) - width / 2, (rect.y + rect.height / 2) - height / 2);
return this;
}
代码示例来源:origin: libgdx/libgdx
final float y2 = y1 + region.getRegionHeight() * unitScale;
imageBounds.set(x1, y1, x2 - x1, y2 - y1);
if (viewBounds.contains(imageBounds) || viewBounds.overlaps(imageBounds)) {
final float u1 = region.getU();
final float v1 = region.getV2();
代码示例来源:origin: libgdx/libgdx
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;
}
}
代码示例来源:origin: libgdx/libgdx
@Test
public void testRectangle () {
Rectangle r1 = new Rectangle(0, 0, 1, 1);
Rectangle r2 = new Rectangle(1, 0, 2, 1);
assertTrue(r1.overlaps(r1));
assertFalse(r1.overlaps(r2));
assertTrue(r1.contains(0, 0));
}
}
代码示例来源:origin: BrentAureli/SuperMario
public InteractiveTileObject(PlayScreen screen, MapObject object){
this.object = object;
this.screen = screen;
this.world = screen.getWorld();
this.map = screen.getMap();
this.bounds = ((RectangleMapObject) object).getRectangle();
BodyDef bdef = new BodyDef();
FixtureDef fdef = new FixtureDef();
PolygonShape shape = new PolygonShape();
bdef.type = BodyDef.BodyType.StaticBody;
bdef.position.set((bounds.getX() + bounds.getWidth() / 2) / MarioBros.PPM, (bounds.getY() + bounds.getHeight() / 2) / MarioBros.PPM);
body = world.createBody(bdef);
shape.setAsBox(bounds.getWidth() / 2 / MarioBros.PPM, bounds.getHeight() / 2 / MarioBros.PPM);
fdef.shape = shape;
fixture = body.createFixture(fdef);
}
代码示例来源:origin: libgdx/libgdx
public static boolean overlaps (Rectangle r1, Rectangle r2) {
return r1.overlaps(r2);
}
代码示例来源:origin: Catacomb-Snatch/Catacomb-Snatch
public void setViewport(float x, float y, float w, float h) {
if (viewport == null) {
viewport = new Rectangle(x, y, w, h);
} else {
viewport.set(x, y, w, h);
}
}
代码示例来源:origin: libgdx/libgdx
if(density == -1) density = boundRect.getWidth()/region.getRegionWidth();
gridWidth = boundRect.getWidth() / density;
gridHeight = regionAspectRatio * gridWidth;
rows = (int) Math.ceil(boundRect.getHeight() / gridHeight);
代码示例来源:origin: libgdx/libgdx
@Test
public void testFromString () {
assertEquals(new Rectangle(5f, -4.1f, 0.03f, -0.02f), new Rectangle().fromString("[5.0,-4.1,0.03,-0.02]"));
}
}
代码示例来源:origin: libgdx/libgdx
@Test
public void testToString () {
assertEquals("[5.0,-4.1,0.03,-0.02]", new Rectangle(5f, -4.1f, 0.03f, -0.02f).toString());
}
代码示例来源:origin: libgdx/libgdx
/** Moves this rectangle so that its center point is located at a given position
* @param x the position's x
* @param y the position's y
* @return this for chaining */
public Rectangle setCenter (float x, float y) {
setPosition(x - width / 2, y - height / 2);
return this;
}
代码示例来源:origin: libgdx/libgdx
final float y2 = y1 + region.getRegionHeight() * unitScale;
imageBounds.set(x1, y1, x2 - x1, y2 - y1);
if (viewBounds.contains(imageBounds) || viewBounds.overlaps(imageBounds)) {
final float u1 = region.getU();
final float v1 = region.getV2();
代码示例来源:origin: libgdx/libgdx
koalaRect.set(koala.position.x, koala.position.y, Koala.WIDTH, Koala.HEIGHT);
int startX, startY, endX, endY;
if (koala.velocity.x > 0) {
koalaRect.x += koala.velocity.x;
for (Rectangle tile : tiles) {
if (koalaRect.overlaps(tile)) {
koala.velocity.x = 0;
break;
koalaRect.y += koala.velocity.y;
for (Rectangle tile : tiles) {
if (koalaRect.overlaps(tile)) {
代码示例来源:origin: bladecoder/bladecoder-adventure-engine
Rectangle boundingRectangle = a.getBBox().getBoundingRectangle();
x = boundingRectangle.getX() + boundingRectangle.getWidth() / 2;
y = boundingRectangle.getY() + boundingRectangle.getHeight();
代码示例来源:origin: libgdx/libgdx
public static boolean overlaps (Rectangle r1, Rectangle r2) {
return r1.overlaps(r2);
}
代码示例来源:origin: libgdx/libgdx
if(density == -1) density = boundRect.getWidth()/region.getRegionWidth();
gridWidth = boundRect.getWidth() / density;
gridHeight = regionAspectRatio * gridWidth;
rows = (int) Math.ceil(boundRect.getHeight() / gridHeight);
代码示例来源:origin: libgdx/libgdx
/** Fits this rectangle around another rectangle while maintaining aspect ratio. This scales and centers the rectangle to the
* other rectangle (e.g. Having a camera translate and scale to show a given area)
* @param rect the other rectangle to fit this rectangle around
* @return this rectangle for chaining
* @see Scaling */
public Rectangle fitOutside (Rectangle rect) {
float ratio = getAspectRatio();
if (ratio > rect.getAspectRatio()) {
// Wider than tall
setSize(rect.height * ratio, rect.height);
} else {
// Taller than wide
setSize(rect.width, rect.width / ratio);
}
setPosition((rect.x + rect.width / 2) - width / 2, (rect.y + rect.height / 2) - height / 2);
return this;
}
内容来源于网络,如有侵权,请联系作者删除!