Java Code Examples for com.badlogic.gdx.utils.viewport.Viewport#getWorldWidth()

The following examples show how to use com.badlogic.gdx.utils.viewport.Viewport#getWorldWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VfxWidgetGroup.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
private void performPendingResize() {
    if (!resizePending) return;

    final int width;
    final int height;

    // Size may be zero if the widget wasn't laid out yet.
    if ((int)getWidth() == 0 || (int)getHeight() == 0) {
        // If the size of the widget is not defined,
        // just resize to a small buffer to keep the memory footprint low.
        width = 16;
        height = 16;

    } else if (matchWidgetSize) {
        // Set buffer to match the size of the widget.
        width = MathUtils.floor(getWidth());
        height = MathUtils.floor(getHeight());

    } else {
        // Set buffer to match the screen pixel density.
        Viewport viewport = getStage().getViewport();
        float ppu = viewport.getScreenWidth() / viewport.getWorldWidth();
        width = MathUtils.floor(getWidth() * ppu);
        height = MathUtils.floor(getHeight() * ppu);

        rendererAdapter.updateOwnProjection();
    }

    vfxManager.resize(width, height);

    resizePending = false;
}
 
Example 2
Source File: Boulder.java    From ud405 with MIT License 5 votes vote down vote up
public void init(Viewport viewport){
    position = new Vector2();

    // TODO: Set the initial velocity to zero in both directions
    velocity = new Vector2(0, 0);

    radius = viewport.getWorldWidth() * RADIUS_RATIO;
    position.y = viewport.getWorldHeight() + radius;
    Random random = new Random();
    position.x = random.nextFloat() * (viewport.getWorldWidth() - 2 * radius) + radius;
}
 
Example 3
Source File: BouncingBall.java    From ud405 with MIT License 5 votes vote down vote up
public void init(Viewport viewport) {
    position = new Vector2(viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2);
    velocity = new Vector2();
    radiusMultiplier = 1;
    radius = BASE_RADIUS * radiusMultiplier;
    randomKick();
}
 
Example 4
Source File: Boulder.java    From ud405 with MIT License 5 votes vote down vote up
public void init(Viewport viewport){
    position = new Vector2();

    // TODO: Set the initial velocity to zero in both directions
    velocity = new Vector2(0, -200);

    radius = viewport.getWorldWidth() * RADIUS_RATIO;
    position.y = viewport.getWorldHeight() + radius;
    Random random = new Random();
    position.x = random.nextFloat() * (viewport.getWorldWidth() - 2 * radius) + radius;
}
 
Example 5
Source File: BouncingBall.java    From ud405 with MIT License 5 votes vote down vote up
public void init(Viewport viewport) {
    position = new Vector2(viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2);
    velocity = new Vector2();
    radiusMultiplier = 1;
    radius = BASE_RADIUS * radiusMultiplier;
    radiusMultiplier = 1;
}
 
Example 6
Source File: BouncingBall.java    From ud405 with MIT License 5 votes vote down vote up
public void init(Viewport viewport) {
    this.viewport = viewport;
    position = new Vector2(viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2);
    velocity = new Vector2();
    baseRadius = RADIUS_FACTOR * Math.min(viewport.getWorldWidth(), viewport.getWorldHeight());
    radiusMultiplier = 1;
}
 
Example 7
Source File: BouncingBall.java    From ud405 with MIT License 5 votes vote down vote up
public void init(Viewport viewport) {
    position = new Vector2(viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2);
    velocity = new Vector2();
    radiusMultiplier = 1;
    radius = BASE_RADIUS * radiusMultiplier;
    radiusMultiplier = 1;
}
 
Example 8
Source File: BouncingBall.java    From ud405 with MIT License 4 votes vote down vote up
public void init(Viewport viewport) {
    position = new Vector2(viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2);
    velocity = new Vector2();
    radius = RADIUS_FACTOR * Math.min(viewport.getWorldWidth(), viewport.getWorldHeight());
    randomKick();
}
 
Example 9
Source File: BouncingBall.java    From ud405 with MIT License 4 votes vote down vote up
public void init(Viewport viewport) {
    position = new Vector2(viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2);
    velocity = new Vector2();
    radius = RADIUS_FACTOR * Math.min(viewport.getWorldWidth(), viewport.getWorldHeight());
    randomKick();
}
 
Example 10
Source File: BouncingBall.java    From ud405 with MIT License 4 votes vote down vote up
public void init(Viewport viewport) {
    position = new Vector2(viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2);
    velocity = new Vector2();
    randomKick();
}
 
Example 11
Source File: SplitViewport.java    From gdx-vr with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the viewport at (row, column) and sets it as the currently active
 * one. The top left sub viewport is (0, 0).
 * 
 * @param row
 *            The index of the row with the viewport to be activated. Starts
 *            at 0.
 * @param column
 *            The index of the column with the viewport to be activated.
 *            Starts at 0.
 * @param centerCamera
 *            Whether the subView should center the camera or not.
 */
public void activateSubViewport(int row, int column, boolean centerCamera) {
	validateCoordinates(row, column);

	Array<SubView> rowMap = subViews.get(row);
	Viewport viewport = rowMap.get(column).viewport;

	// update the viewport simulating a smaller sub view
	calculateSubViewportArea(row, column, subViewportArea);
	viewport.update((int) subViewportArea.width, (int) subViewportArea.height, centerCamera);

	// store the current world size so we can restore it in case it gets
	// changed now
	float originalWorldWidth = viewport.getWorldWidth();
	float originalWorldHeight = viewport.getWorldHeight();

	// some scaling strategies will scale the viewport bigger than the
	// allowed sub view, so we need to limit it
	if (viewport.getScreenWidth() > subViewportArea.width) {
		float offcutWidth = viewport.getScreenWidth() - subViewportArea.width;
		viewport.setScreenWidth((int) subViewportArea.width);
		viewport.setWorldWidth(viewport.getWorldWidth() - offcutWidth);
		viewport.setScreenX((int) (viewport.getScreenX() + offcutWidth / 2));
	}
	if (viewport.getScreenHeight() > subViewportArea.height) {
		float offcutHeight = viewport.getScreenHeight() - subViewportArea.height;
		viewport.setScreenHeight((int) subViewportArea.height);
		viewport.setWorldHeight(viewport.getWorldHeight() - offcutHeight);
		viewport.setScreenY((int) (viewport.getScreenY() + offcutHeight / 2));
	}

	// now shift it to the correct place
	viewport.setScreenX((int) (viewport.getScreenX() + subViewportArea.x));
	viewport.setScreenY((int) (viewport.getScreenY() + subViewportArea.y));

	// we changed the viewport parameters, now we need to update once more
	// to correct the glViewport
	viewport.apply();

	// restore the original world width after the glViewport has been set
	viewport.setWorldWidth(originalWorldWidth);
	viewport.setWorldHeight(originalWorldHeight);

	activeViewport = viewport;
}
 
Example 12
Source File: ScreenPositionAction.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
@Override
public boolean run(VerbRunner cb) {
	Scene s = actor.getScene(w);

	BaseActor a = s.getActor(actor.getActorId(), true);

	if (position != null) {
		float scale = EngineAssetManager.getInstance().getScale();

		Viewport viewport = ((SceneScreen) BladeEngine.getAppUI().getScreen(Screens.SCENE_SCREEN)).getViewport();

		Vector3 v = new Vector3(position.x * scale, position.y * scale, 0);

		if (anchor == Anchor.CENTER) {
			v.x += viewport.getWorldWidth() / 2;
			v.y += viewport.getWorldHeight() / 2;
		} else if (anchor == Anchor.TOP_LEFT) {
			v.x += 0;
			v.y += viewport.getWorldHeight();
		} else if (anchor == Anchor.TOP_RIGHT) {
			v.x += viewport.getWorldWidth();
			v.y += viewport.getWorldHeight();
		} else if (anchor == Anchor.BOTTOM_RIGHT) {
			v.x += viewport.getWorldWidth();
			v.y += 0;
		} else if (anchor == Anchor.BOTTOM_LEFT) {
			v.x += 0;
			v.y += 0;
		} else if (anchor == Anchor.TOP) {
			v.x += viewport.getWorldWidth() / 2;
			v.y += viewport.getWorldHeight();
		} else if (anchor == Anchor.BOTTOM) {
			v.x += viewport.getWorldWidth() / 2;
			v.y += 0;
		} else if (anchor == Anchor.LEFT) {
			v.x += 0;
			v.y += viewport.getWorldHeight() / 2;
		} else if (anchor == Anchor.RIGHT) {
			v.x += viewport.getWorldWidth();
			v.y += viewport.getWorldHeight() / 2;
		}

		// viewport.project(v);

		v.x *= viewport.getScreenWidth() / viewport.getWorldWidth();
		v.y *= viewport.getScreenHeight() / viewport.getWorldHeight();

		// v.y = viewport.getScreenHeight() - v.y;
		v.y = Gdx.graphics.getHeight() - v.y;

		if (w.getUIActors().getActors().contains(a))
			w.getUIActors().getCamera().unproject(v, 0, 0, viewport.getScreenWidth(), viewport.getScreenHeight());
		else
			w.getCurrentScene().getCamera().unproject(v, 0, 0, viewport.getScreenWidth(),
					viewport.getScreenHeight());

		a.setPosition(v.x, v.y);
	}

	return false;
}