Java Code Examples for com.badlogic.gdx.scenes.scene2d.Stage#getWidth()

The following examples show how to use com.badlogic.gdx.scenes.scene2d.Stage#getWidth() . 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: Window.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
void keepWithinStage () {
	if (!keepWithinStage) return;
	Stage stage = getStage();
	if (getParent() == stage.getRoot()) {
		float parentWidth = stage.getWidth();
		float parentHeight = stage.getHeight();
		if (getX() < 0) setX(0);
		if (getRight() > parentWidth) setX(parentWidth - getWidth());
		if (getY() < 0) setY(0);
		if (getTop() > parentHeight) setY(parentHeight - getHeight());
	}
}
 
Example 2
Source File: ShowDragDieAnimation.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override protected Actor getActorToShow() {
    PvePlayState playState = resources.get("playState");
    Stage stage = resources.get("stage");
    float x = stage.getWidth() / 2 - 10;
    float y = 36;

    Vector2 stagePosition = getTarget().localToStageCoordinates(new Vector2(x, y));
    Vector2 stageTarget = playState.world.getController(ViewController.class).getScreenRectangle(2, 1).getCenter(new Vector2());

    TutorialUpArrow arrow = new TutorialUpArrow();
    arrow.setPosition(x, y);
    arrow.setHeight(stageTarget.y - stagePosition.y);
    return arrow;
}
 
Example 3
Source File: Hint.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public void show(Stage stage, float stageX, float stageY) {
    if (shown || stage == null)
        return;
    shown = true;
    stage.addActor(table);
    updateTableWidth(Float.MAX_VALUE);
    // if actor is too high, try to place it left or right
    if (table.getHeight() + stageY + TOUCH_OFFSET > stage.getHeight() - SCREEN_EDGE_OFFSET) {
        if (stageX > stage.getWidth() / 2) {
            //left
            updateTableWidth(stageX - TOUCH_OFFSET - SCREEN_EDGE_OFFSET);
            table.setX(stageX - TOUCH_OFFSET - table.getWidth());
        } else {
            //right
            updateTableWidth(stage.getWidth() - stageX - TOUCH_OFFSET - SCREEN_EDGE_OFFSET);
            table.setX(stageX + TOUCH_OFFSET);
        }
        table.setY(MathUtils.clamp(stageY - table.getHeight() / 2, SCREEN_EDGE_OFFSET, stage.getHeight() - table.getHeight() - SCREEN_EDGE_OFFSET));
    } else {
        table.setPosition(
            MathUtils.clamp(stageX - table.getWidth() / 2, SCREEN_EDGE_OFFSET, stage.getWidth() - table.getWidth() - SCREEN_EDGE_OFFSET),
            stageY + TOUCH_OFFSET
        );
    }
    table.clearActions();
    table.getColor().a = 0;
    table.addAction(alpha(1, 0.25f));
}
 
Example 4
Source File: PathFinderTests.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@Override
public void create () {
	Gdx.gl.glClearColor(.3f, .3f, .3f, 1);

	skin = new Skin(Gdx.files.internal("data/uiskin.json"));

	// Enable color markup
	BitmapFont font = skin.get("default-font", BitmapFont.class);
	font.getData().markupEnabled = true;

	stage = new Stage();
	stage.setDebugAll(DEBUG_STAGE);
	stageWidth = stage.getWidth();
	stageHeight = stage.getHeight();

	Gdx.input.setInputProcessor(new InputMultiplexer(stage));

	Stack stack = new Stack();
	stage.addActor(stack);
	stack.setSize(stageWidth, stageHeight);
	testsTable = new Table();
	stack.add(testsTable);

	// Create behavior selection window
	List<String> testList = createTestList();
	algorithmSelectionWindow = addBehaviorSelectionWindow("Path Finder Tests", testList, 0, -1);

	// Set selected test
	changeTest(0);

	stage.addActor(new FpsLabel("FPS: ", skin));
}
 
Example 5
Source File: MessageTests.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@Override
public void create () {
	Gdx.gl.glClearColor(.3f, .3f, .3f, 1);

	skin = new Skin(Gdx.files.internal("data/uiskin.json"));

	stage = new Stage();
	stage.setDebugAll(DEBUG_STAGE);
	stageWidth = stage.getWidth();
	stageHeight = stage.getHeight();

	Gdx.input.setInputProcessor(stage);

	// Add translucent panel (it's only visible when AI is paused)
	final Image translucentPanel = new Image(skin, "translucent");
	translucentPanel.setSize(stageWidth, stageHeight);
	translucentPanel.setVisible(false);
	stage.addActor(translucentPanel);

	// Create test selection window
	List<String> testList = createTestList();
	testSelectionWindow = addTestSelectionWindow("Tests", testList, 0, -1);

	// Create status bar
	Table statusBar = new Table(skin);
	statusBar.left().bottom();
	statusBar.row().height(26);
	statusBar.add(pauseButton = new PauseButton(translucentPanel, skin)).width(90).left();
	statusBar.add(new FpsLabel("FPS: ", skin)).padLeft(15);
	statusBar.add(testDescriptionLabel = new Label("", skin)).padLeft(15);
	stage.addActor(statusBar);

	// Set selected behavior
	changeTest(0);
}
 
Example 6
Source File: SteeringBehaviorsTest.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
@Override
public void create () {
	Gdx.gl.glClearColor(.3f, .3f, .3f, 1);

	greenFish = new TextureRegion(new Texture("data/green_fish.png"));
	cloud = new TextureRegion(new Texture("data/particle-cloud.png"));
	badlogicSmall = new TextureRegion(new Texture("data/badlogicsmall.jpg"));
	target = new TextureRegion(new Texture("data/target.png"));

	skin = new Skin(Gdx.files.internal("data/uiskin.json"));

	stage = new Stage();
	stage.setDebugAll(DEBUG_STAGE);
	stageWidth = stage.getWidth();
	stageHeight = stage.getHeight();

	Gdx.input.setInputProcessor(new InputMultiplexer(stage));

	// Add translucent panel (it's only visible when AI is paused)
	final Image translucentPanel = new Image(skin, "translucent");
	translucentPanel.setSize(stageWidth, stageHeight);
	translucentPanel.setVisible(false);
	stage.addActor(translucentPanel);

	// Create test selection window
	Array<List<String>> engineTests = new Array<List<String>>();
	for (int k = 0; k < tests.length; k++) {
		engineTests.add(createTestList(k));
	}
	testSelectionWindow = addTestSelectionWindow("Behaviors", ENGINES, engineTests, 0, -1);

	// Create status bar
	Table statusBar = new Table(skin);
	statusBar.left().bottom();
	statusBar.row().height(26);
	statusBar.add(pauseButton = new PauseButton(translucentPanel, skin)).width(90).left();
	statusBar.add(new FpsLabel("FPS: ", skin)).padLeft(15);
	statusBar.add(testHelpLabel = new Label("", skin)).padLeft(15);
	stage.addActor(statusBar);

	// Set selected behavior
	changeTest(0, 0);
}