/** * @param group an empty group to be the parent * @return the group with the current selection */ public Group createGroup(Group group) { // New group has the same transformation as this group.setBounds(getX(), getY(), getWidth(), getHeight()); group.setOrigin(getOriginX(), getOriginY()); group.setRotation(getRotation()); group.setScale(getScaleX(), getScaleY()); // Each children in the group must be contained by the new group Array<Actor> children = getChildren(); children.sort( new Comparator<Actor>() { @Override public int compare(Actor actor, Actor actor2) { return ((SelectionGhost) actor).getRepresentedActor().getZIndex() - ((SelectionGhost) actor2).getRepresentedActor().getZIndex(); } }); for (Actor actor : children) { SelectionGhost ghost = (SelectionGhost) actor; Actor representedActor = ghost.getRepresentedActor(); representedActor.setPosition(ghost.getX(), ghost.getY()); representedActor.setRotation(ghost.getRotation()); representedActor.setScale(ghost.getScaleX(), ghost.getScaleY()); group.addActor(representedActor); } return group; }
@Override public void setRotation(float degrees) { if (dataVO.type == LightType.CONE) { lightObject.setDirection(direction + degrees); } super.setRotation(degrees); }
/** * Updates transformation of the represented actor to match the selection ghost transformation */ private void updateTransformation() { Actor parent = representedActor.getParent(); this.localToAscendantCoordinates(parent, tmp1.set(0, 0)); this.localToAscendantCoordinates(parent, tmp2.set(getWidth(), 0)); this.localToAscendantCoordinates(parent, tmp3.set(0, getHeight())); modifier.applyTransformation(representedActor, tmp1, tmp2, tmp3); representedActor.setRotation(startingRotation + getParent().getRotation()); }
@Override public void control(Actor actor, float deltaSeconds) { long deltaMillis = (long) (deltaSeconds * 1000); timePeriodManager.update(deltaMillis); float angle; float normalizedValue; int subPeriod = timePeriodManager.getCurrentSubPeriod(); // Rotate up if (subPeriod == rotateUpSubPeriod) { normalizedValue = timePeriodManager.getNormalizedCurrentSubPeriodTime(); Interpolation interpolation = Interpolation.linear; if (this.interpolation != null) { interpolation = this.interpolation; } angle = interpolation.apply(minAngle, maxAngle, normalizedValue); } // Stall up else if (subPeriod == stallUpSubPeriod) { angle = maxAngle; } // Rotate down else if (subPeriod == rotateDownSubPeriod) { normalizedValue = timePeriodManager.getNormalizedCurrentSubPeriodTime(); Interpolation interpolation = Interpolation.linear; if (this.interpolation != null) { interpolation = this.interpolation; } angle = interpolation.apply(maxAngle, minAngle, normalizedValue); } // Stall up else { angle = minAngle; } actor.setRotation(angle); }
/** * For a given actor computes and applies the transformation to keep the same screen * transformation in a new group * * @param actor * @param parent */ public static void computeTransformFor(Actor actor, Group parent) { Vector2 tmp1 = Pools.obtain(Vector2.class); Vector2 tmp2 = Pools.obtain(Vector2.class); Vector2 tmp3 = Pools.obtain(Vector2.class); Vector2 tmp4 = Pools.obtain(Vector2.class); Vector2 tmp5 = Pools.obtain(Vector2.class); calculateBounds(actor, tmp4, tmp5); Vector2 o = tmp1.set(tmp4.x, tmp4.y); Vector2 t = tmp2.set(tmp4.x + tmp5.x, tmp4.y); Vector2 n = tmp3.set(tmp4.x, tmp4.y + tmp5.y); actor.localToAscendantCoordinates(parent, o); actor.localToAscendantCoordinates(parent, t); actor.localToAscendantCoordinates(parent, n); actor.setRotation(actor.getRotation() + actor.getParent().getRotation()); applyTransformation(actor, o, t, n); Pools.free(tmp1); Pools.free(tmp2); Pools.free(tmp3); Pools.free(tmp4); Pools.free(tmp5); }
/** Adds the specified rotation to the current rotation. */ public void rotate(float amountInDegrees) { setRotation(rotation + amountInDegrees); }
@Override public void render() { Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); if (Gdx.input.isTouched()) { 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); } scale += vScale * Gdx.graphics.getDeltaTime(); if (scale > 1) { scale = 1; vScale = -vScale; } if (scale < 0.5f) { scale = 0.5f; vScale = -vScale; } len = sprites.size; for (int i = 0; i < len; i++) { Actor sprite = sprites.get(i); if (rotateSprites) sprite.rotateBy(-40 * Gdx.graphics.getDeltaTime()); else sprite.setRotation(0); if (scaleSprites) { sprite.setScale(scale); } else { sprite.setScale(1); } } stage.draw(); renderer.begin(ShapeType.Point); renderer.setColor(1, 0, 0, 1); 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); } renderer.end(); fps.setText( "fps: " + Gdx.graphics.getFramesPerSecond() + ", actors " + sprites.size + ", groups " + sprites.size); ui.draw(); }