/** * Returns the position of the Entity. * * @return the position, in Vector2 form */ public Vector2 getOriginPosition() { if (sprite != null) { return new Vector2(sprite.getX() + sprite.getOriginX(), sprite.getY() + sprite.getOriginY()); } else { return new Vector2((edges[0].x + edges[1].x) / 2, (edges[0].y + edges[1].y) / 2); } }
@Override public void render() { camera.update(); // Step the physics simulation forward at a rate of 60hz world.step(1f / 60f, 6, 2); sprite.setPosition( (body.getPosition().x * PIXELS_TO_METERS) - sprite.getWidth() / 2, (body.getPosition().y * PIXELS_TO_METERS) - sprite.getHeight() / 2); sprite.setRotation((float) Math.toDegrees(body2.getAngle())); sprite2.setPosition( (body2.getPosition().x * PIXELS_TO_METERS) - sprite2.getWidth() / 2, (body2.getPosition().y * PIXELS_TO_METERS) - sprite2.getHeight() / 2); sprite2.setRotation((float) Math.toDegrees(body.getAngle())); Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setProjectionMatrix(camera.combined); batch.begin(); batch.draw( sprite, sprite.getX(), sprite.getY(), sprite.getOriginX(), sprite.getOriginY(), sprite.getWidth(), sprite.getHeight(), sprite.getScaleX(), sprite.getScaleY(), sprite.getRotation()); batch.draw( sprite2, sprite2.getX(), sprite2.getY(), sprite2.getOriginX(), sprite2.getOriginY(), sprite2.getWidth(), sprite2.getHeight(), sprite2.getScaleX(), sprite2.getScaleY(), sprite2.getRotation()); batch.end(); }
public void draw(SpriteBatch batch, float parentAlpha) { stateTime += Gdx.graphics.getDeltaTime(); Sprite toRender = currentAnimation.getKeyFrame(stateTime); // -1 to account for the sword below his feet toRender.setPosition(getX(), getY() - 1); toRender.setOrigin( toRender.getX() + toRender.getWidth(), toRender.getY() + toRender.getHeight()); toRender.setRotation(getRotation()); setSize(toRender.getWidth(), toRender.getHeight()); setOrigin(toRender.getOriginX(), toRender.getOriginY()); toRender.draw(batch); if (TheLoveOfRice.DRAW_DEBUG) { drawDebug(batch); } }
public Sprite getSprite(VisAssetDescriptor descriptor, float pixelsPerUnit) { Sprite sprite = new Sprite(getRegion(descriptor)); sprite.setSize(sprite.getWidth() / pixelsPerUnit, sprite.getHeight() / pixelsPerUnit); sprite.setOrigin(sprite.getOriginX() / pixelsPerUnit, sprite.getOriginY() / pixelsPerUnit); return sprite; }
/** * Sets the origin position (defined at the center of the image via width and height). * * @param x the x position * @param y the y position */ protected void setOriginPosition(float x, float y) { sprite.setPosition(x - sprite.getOriginX(), y - sprite.getOriginY()); updateSides(); }