Refine search
Stage stage = event.getStage(); dragActor.remove(); // Remove so it cannot be hit (Touchable.disabled isn't enough). dragActor = null; float stageX = event.getStageX() + touchOffsetX, stageY = event.getStageY() + touchOffsetY; Actor hit = event.getStage().hit(stageX, stageY, true); // Prefer touchable actors. if (hit == null) hit = event.getStage().hit(stageX, stageY, false); if (hit != null) { for (int i = 0, n = targets.size; i < n; i++) { Target target = targets.get(i); if (!target.actor.isAscendantOf(hit)) continue; newTarget = target; target.actor.stageToLocalCoordinates(tmpVector.set(stageX, stageY)); break; dragActor = actor; if (actor == null) return; stage.addActor(actor); float actorX = event.getStageX() - actor.getWidth() + dragActorX; float actorY = event.getStageY() + dragActorY; if (actorX < 0) actorX = 0; if (actorY < 0) actorY = 0; if (actorX + actor.getWidth() > stage.getWidth()) actorX = stage.getWidth() - actor.getWidth(); if (actorY + actor.getHeight() > stage.getHeight()) actorY = stage.getHeight() - actor.getHeight(); actor.setPosition(actorX, actorY);
@Override public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); ui.act(Gdx.graphics.getDeltaTime()); ui.draw(); }
@Override public void create () { // create a stage and a camera controller so we can pan the view. stage = new Stage();; camController = new OrthoCamController((OrthographicCamera)stage.getCamera()); // we know it's an ortho cam at this point! Gdx.input.setInputProcessor(camController); // load a dummy texture texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); // populate the stage with some actors and groups. for (int i = 0; i < 5000; i++) { Actor img = new CullableActor("img" + i, texture, (OrthographicCamera)stage.getCamera()); img.setX((float)Math.random() * 480 * 10); img.setY((float)Math.random() * 320 * 10); stage.addActor(img); } // we also want to output the number of visible actors, so we need a SpriteBatch and a BitmapFont batch = new SpriteBatch(); font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); }
@Override public void resize (int width, int height) { super.resize(width, height); hud.getViewport().update(width, height, true); hudWidth = hud.getWidth(); hudHeight = hud.getHeight(); }
public void create () { if (ui != null) return; int w = Gdx.graphics.getWidth(), h = Gdx.graphics.getHeight(); modelBatch = new ModelBatch(); environment = new Environment(); backgroundColor.setColors(new float[] { color.r, color.g, color.b}); models = new Array<Model>(); ModelBuilder builder = new ModelBuilder(); Model xyzModel = builder.createXYZCoordinates(10, new Material(), Usage.Position|Usage.ColorPacked), planeModel = builder.createLineGrid(10, 10, 1, 1, new Material(ColorAttribute.createDiffuse(Color.WHITE)), Usage.Position); models.add(xyzModel); models.add(planeModel); xyzInstance = new ModelInstance(xyzModel); xzPlaneInstance = new ModelInstance(planeModel); ui = new Stage(); fpsLabel = new Label("", skin); pointCountLabel = new Label("", skin); table.add(maxLabel).expandX().left().row(); table.add(playPauseButton).expand().bottom().left().row(); ui.addActor(table);
@Override public void create () { stage = new Stage(); Gdx.input.setInputProcessor(stage); skin = new Skin(Gdx.files.internal("data/uiskin.json")); for (int i = 0; i < 1; i++) { TextButton t = new TextButton("Button" + i, skin); t.setX(MathUtils.random(0, Gdx.graphics.getWidth())); t.setY(MathUtils.random(0, Gdx.graphics.getHeight())); t.setWidth(MathUtils.random(50, 200)); t.setHeight(MathUtils.random(0, 100)); stage.addActor(t); } }
@Override public void render () { Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); stage.screenToStageCoordinates(stageCoords.set(Gdx.input.getX(), Gdx.input.getY())); Actor actor = stage.hit(stageCoords.x, stageCoords.y, true); if (actor != null) actor.setColor((float)Math.random(), (float)Math.random(), (float)Math.random(), 0.5f + 0.5f * (float)Math.random()); Array<Actor> actors = stage.getActors(); int len = actors.size; if (rotateSprites) { for (int i = 0; i < len; i++) actors.get(i).rotateBy(Gdx.graphics.getDeltaTime() * 10); stage.draw(); len = actors.size; for (int i = 0; i < len; i++) { Group group = (Group)actors.get(i); renderer.point(group.getX() + group.getOriginX(), group.getY() + group.getOriginY(), 0); fps.setText("fps: " + Gdx.graphics.getFramesPerSecond() + ", actors " + sprites.size + ", groups " + sprites.size); ui.draw();
private void setContainerPosition (Actor actor, float x, float y) { this.targetActor = actor; Stage stage = actor.getStage(); if (stage == null) return; container.pack(); float offsetX = manager.offsetX, offsetY = manager.offsetY, dist = manager.edgeDistance; Vector2 point = actor.localToStageCoordinates(tmp.set(x + offsetX, y - offsetY - container.getHeight())); if (point.y < dist) point = actor.localToStageCoordinates(tmp.set(x + offsetX, y + offsetY)); if (point.x < dist) point.x = dist; if (point.x + container.getWidth() > stage.getWidth() - dist) point.x = stage.getWidth() - dist - container.getWidth(); if (point.y + container.getHeight() > stage.getHeight() - dist) point.y = stage.getHeight() - dist - container.getHeight(); container.setPosition(point.x, point.y); point = actor.localToStageCoordinates(tmp.set(actor.getWidth() / 2, actor.getHeight() / 2)); point.sub(container.getX(), container.getY()); container.setOrigin(point.x, point.y); }
public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); float bottomLeftX = Gdx.graphics.getWidth() / 2 - graphSize / 2, bottomLeftY = Gdx.graphics.getHeight() / 2 - graphSize / 2; if (text.length() > 4) text = text.substring(0, text.lastIndexOf('.') + 3); text = "duration: " + text + " s (ctrl + scroll to change)"; stage.getBatch().begin(); list.getStyle().font.draw(stage.getBatch(), text, bottomLeftX + graphSize / 2, bottomLeftY + graphSize + list.getStyle().font.getLineHeight(), 0, Align.center, false); stage.getBatch().end(); lastY = y; time += Gdx.graphics.getDeltaTime(); if (time > duration) { startPosition.set(targetPosition); // set startPosition to targetPosition for next click renderer.end(); stage.act(); stage.draw();
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); stage = new Stage(new ScreenViewport()); group.setX((float)Math.random() * (stage.getWidth() - NUM_SPRITES * (32 + SPACING))); group.setY((float)Math.random() * (stage.getHeight() - NUM_SPRITES * (32 + SPACING))); group.setOrigin(loc, loc); stage.addActor(group); ui = new Stage(new ScreenViewport()); blend.setY(ui.getHeight() - 64); shapeActor.setBounds(0, 0, 100, 150); shapeActor.setOrigin(50, 75); shapeActor.debug(); sprites.add(shapeActor); shapeGroup.setTouchable(Touchable.childrenOnly); shapeGroup.addActor(shapeActor); stage.addActor(shapeGroup); ui.addActor(blend); ui.addActor(rotate); ui.addActor(scale); ui.addActor(fps);
public void run () { if (showTooltip == null || showTooltip.targetActor == null) return; Stage stage = showTooltip.targetActor.getStage(); if (stage == null) return; stage.addActor(showTooltip.container); showTooltip.container.toFront(); shown.add(showTooltip); showTooltip.container.clearActions(); showAction(showTooltip); if (!showTooltip.instant) { time = subsequentTime; resetTask.cancel(); } } };
public void draw (Batch batch, float parentAlpha) { Stage stage = getStage(); if (stage.getKeyboardFocus() == null) stage.setKeyboardFocus(this); keepWithinStage(); if (style.stageBackground != null) { stageToLocalCoordinates(tmpPosition.set(0, 0)); stageToLocalCoordinates(tmpSize.set(stage.getWidth(), stage.getHeight())); drawStageBackground(batch, parentAlpha, getX() + tmpPosition.x, getY() + tmpPosition.y, getX() + tmpSize.x, getY() + tmpSize.y); } super.draw(batch, parentAlpha); }
public void show (Stage stage) { if (list.isTouchable()) return; stage.addActor(this); stage.addCaptureListener(hideListener); stage.addListener(list.getKeyListener()); selectBox.localToStageCoordinates(screenPosition.set(0, 0)); float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight(); boolean below = true; if (height > heightBelow) { Actor actor = stage.getScrollFocus(); if (actor != null && !actor.isDescendantOf(this)) previousScrollFocus = actor; stage.setScrollFocus(this);
public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); stage.draw(); // check how many actors are visible. Array<Actor> actors = stage.getActors(); int numVisible = 0; for (int i = 0; i < actors.size; i++) { numVisible += ((CullableActor)actors.get(i)).visible ? 1 : 0; } batch.begin(); font.draw(batch, "Visible: " + numVisible + ", fps: " + Gdx.graphics.getFramesPerSecond(), 20, 30); batch.end(); }
public void keepWithinStage () { if (!keepWithinStage) return; Stage stage = getStage(); if (stage == null) return; Camera camera = stage.getCamera(); if (camera instanceof OrthographicCamera) { OrthographicCamera orthographicCamera = (OrthographicCamera)camera; float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, getY(Align.right), Align.right); if (getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, getY(Align.left), Align.left); if (getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top); if (getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom); } else 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()); } }
@Override public void tick(float delta) { // Draw background if (drawBackground && background != null) { getBatch().begin(); getBatch().setColor(backgroundColor); getBatch().draw(background, 0, 0, Screen.getWidth(), Screen.getHeight()); getBatch().end(); } // Similar to Google's Android "Project Butter": // Updating mouse dependent stuff in render() if (!Gdx.input.isTouched()) { mousePos = screenToStageCoordinates(mousePos.set(Gdx.input.getX(), Gdx.input.getY())); for (Actor a : getActors()) { currentActorRect.set(a.getX(), a.getY(), a.getWidth(), a.getHeight()); for (EventListener el : a.getListeners()) { if (!(el instanceof InputListener)) continue; InputListener il = (InputListener) el; if (currentActorRect.contains(mousePos.x, mousePos.y)) { il.enter(null, mousePos.x, mousePos.y, -1, null); } else { il.exit(null, mousePos.x, mousePos.y, -1, null); } } } } super.draw(); getBatch().begin(); }
stage.act(Gdx.graphics.getDeltaTime()); stage.getBatch().disableBlending(); Group root = stage.getRoot(); Array<Actor> actors = root.getChildren(); stage.draw(); } else { batch.getProjectionMatrix().setToOrtho2D(0, 0, 24, 12); font.setColor(0, 0, 1, 1); font.getData().setScale(2); font.draw(batch, "fps: " + Gdx.graphics.getFramesPerSecond() + (useStage ? ", stage" : "sprite"), 10, 40); batch.end();
public void validate () { if (!layoutEnabled) return; Group parent = getParent(); if (fillParent && parent != null) { float parentWidth, parentHeight; Stage stage = getStage(); if (stage != null && parent == stage.getRoot()) { parentWidth = stage.getWidth(); parentHeight = stage.getHeight(); } else { parentWidth = parent.getWidth(); parentHeight = parent.getHeight(); } setSize(parentWidth, parentHeight); } if (!needsLayout) return; needsLayout = false; layout(); }