/** Moves this rectangle so that its center point is located at a given position * @param position the position * @return this for chaining */ public Rectangle setCenter (Vector2 position) { setPosition(position.x - width / 2, position.y - height / 2); return this; }
/** 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; }
/** 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; }
/** Moves this rectangle so that its center point is located at a given position * @param position the position * @return this for chaining */ public Rectangle setCenter (Vector2 position) { setPosition(position.x - width / 2, position.y - height / 2); return this; }
/** Fits this rectangle into another rectangle while maintaining aspect ratio. This scales and centers the rectangle to the * other rectangle (e.g. Scaling a texture within a arbitrary cell without squeezing) * @param rect the other rectangle to fit this rectangle inside * @return this rectangle for chaining * @see Scaling */ public Rectangle fitInside (Rectangle rect) { float ratio = getAspectRatio(); if (ratio < rect.getAspectRatio()) { // Taller than wide setSize(rect.height * ratio, rect.height); } else { // Wider than tall setSize(rect.width, rect.width / ratio); } setPosition((rect.x + rect.width / 2) - width / 2, (rect.y + rect.height / 2) - height / 2); return this; }
/** Fits this rectangle into another rectangle while maintaining aspect ratio. This scales and centers the rectangle to the * other rectangle (e.g. Scaling a texture within a arbitrary cell without squeezing) * @param rect the other rectangle to fit this rectangle inside * @return this rectangle for chaining * @see Scaling */ public Rectangle fitInside (Rectangle rect) { float ratio = getAspectRatio(); if (ratio < rect.getAspectRatio()) { // Taller than wide setSize(rect.height * ratio, rect.height); } else { // Wider than tall setSize(rect.width, rect.width / ratio); } setPosition((rect.x + rect.width / 2) - width / 2, (rect.y + rect.height / 2) - height / 2); return this; }
/** 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; }
/** 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; }
/** 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; }
/** Moves this rectangle so that its center point is located at a given position * @param position the position * @return this for chaining */ public Rectangle setCenter (Vector2 position) { setPosition(position.x - width / 2, position.y - height / 2); return this; }
public void updateBounds(){ bounds.setPosition(position.x, position.y); }
public class BoxerSprite extends AnimatedSprite { boolean isPunching = false; Rectangle fist; public BoxerSprite(float pX, float pY, float pWidth, float pHeight, ITiledTextureRegion pTiledTextureRegion, ITiledSpriteVertexBufferObject pTiledSpriteVertexBufferObject) { super(pX, pY, pWidth, pHeight, pTiledTextureRegion, pTiledSpriteVertexBufferObject); //Create a "fist" object within your boxer sprite fist = new Rectangle(fistX, fistY, fistWidth, fistHeight, vertexBufferObjectManager); //Use setPosition to move the fist to the appropriate location during the animation. fist.setPosition(pX, pY); } }
void setPosition(int x, int y) { this.bounds.setPosition(x, y); if (buttonFont != null) { rerenderLabel(); } }
public void reposition(float x){ posTopTube.set(x, rand.nextInt(FLUCTUATION) + LOWEST_OPENING + TUBE_GAP); posBottomTube.set(x, posTopTube.y - TUBE_GAP - bottomTube.getHeight()); boundsTop.setPosition(x, posTopTube.y); boundsBottom.setPosition(x, posBottomTube.y); }
public void reposition(float x){ posTopTube.set(x, rand.nextInt(FLUCTUATION) + TUBE_GAP + LOWEST_OPENING); posBotTube.set(x, posTopTube.y - TUBE_GAP - bottomTube.getHeight()); boundsTop.setPosition(posTopTube.x, posTopTube.y); boundsBot.setPosition(posBotTube.x, posBotTube.y); }
void update() { position.x -= speed; if (position.x < -imgAsteroid.getWidth()) recreate(); for (int i = 0; i < asteroids.length; i++) if (!this.equals(asteroids[i])) if (asteroids[i].hitBox.overlaps(hitBox)) if (asteroids[i].position.y < position.y) { asteroids[i].position.y -= asteroids[i].speed / 6; asteroids[i].position.x -= asteroids[i].speed / 6; //asteroids[i].speed += 0.5; position.y += speed / 6; position.x += speed / 3; //speed -= 0.5; } else { asteroids[i].position.y += asteroids[i].speed / 6; asteroids[i].position.x -= asteroids[i].speed / 6; //asteroids[i].speed += 1; position.y -= speed / 6; position.x += speed / 3; //speed -= 0.5; } hitBox.setPosition(position); } }
/** 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; }
/** Fits this rectangle into another rectangle while maintaining aspect ratio. This scales and centers the rectangle to the * other rectangle (e.g. Scaling a texture within a arbitrary cell without squeezing) * @param rect the other rectangle to fit this rectangle inside * @return this rectangle for chaining * @see Scaling */ public Rectangle fitInside (Rectangle rect) { float ratio = getAspectRatio(); if (ratio < rect.getAspectRatio()) { // Taller than wide setSize(rect.height * ratio, rect.height); } else { // Wider than tall setSize(rect.width, rect.width / ratio); } setPosition((rect.x + rect.width / 2) - width / 2, (rect.y + rect.height / 2) - height / 2); return this; }
public void update(float dt){ birdAnimation.update(dt); if(position.y > 0) velocity.add(0, GRAVITY, 0); velocity.scl(dt); position.add(MOVEMENT * dt, velocity.y, 0); if(position.y < 0) position.y = 0; velocity.scl(1/dt); bounds.setPosition(position.x, position.y); }
actor1.getHeight() * actor1.getScaleY() ); rect1.setPosition( actor1.getX() - (actor1.getOriginX() * actor1.getScaleX() - actor1.getOriginX()), actor1.getY() - (actor1.getOriginY() * actor1.getScaleY() - actor1.getOriginY()) actor2.getHeight() * actor2.getScaleY() ); rect2.setPosition( actor2.getX() - (actor2.getOriginX() * actor2.getScaleX() - actor2.getOriginX()), actor2.getY() - (actor2.getOriginY() * actor2.getScaleY() - actor2.getOriginY())