private Group createActorGroup (TextureRegionDrawable bob) { Actor main = new DrawableActor(bob); main.setPosition(0, 0, Align.center); Actor hat = new DrawableActor(bob) { @Override public void act (float delta) { rotateBy(delta * -300); } }; hat.setOrigin(Align.center); hat.setScale(0.5f); hat.setPosition(0, 21, Align.center); Group group = new Group() { @Override public void act (float delta) { rotateBy(delta * 120); setScale(0.9f + 0.2f * MathUtils.cos(MathUtils.degreesToRadians * getRotation())); super.act(delta); } }; group.addActor(main); group.addActor(hat) ; // group.setTransform(false); float margin = 35; float x = MathUtils.random(margin, stage.getWidth() - margin); float y = MathUtils.random(margin, stage.getHeight() - margin); group.setPosition(x, y); group.setRotation(MathUtils.random(0, 360)); return group; }
/** * Sets the position of the actor's bottom left corner. * * @param x * @param y */ @Override public void setPosition(float x, float y) { super.setPosition(x, y); setBounds(x, y, getWidth(), getHeight()); }
/** * set the position use the camera's viewPort . the zero-zero is on the left bottom */ public void setPosition(final float x,final float y){ super.setPosition(x, y); model.body.setTransform(new Vector2(x,y).add(model.drawableOffsetX,model.drawableOffsetY).scl(1/RADIO), model.body.getAngle()); }
public Group createSuperRoot() { Group SRoot = new Group(); SRoot.setSize(getFullWidth(), getFullHeight()); SRoot.setPosition(game.getCenterX(), game.getCenterY(), Align.center); return SRoot; }
private void updateGroupProperties( ExternalGroupModel model, Group group){ group.setName( model.getName()); model.setWidth( group.getWidth()); model.setHeight( group.getHeight()); // For example .. <FriendsPanel > in top xml and its implementation's root group (FriendsPanel.xml file's) // should both be visible=true in order to set whole group visible, if at least one of them set to false // whole group will be invisible. group.setVisible(model.isVisible() && group.isVisible()); Vector2 screenPos; if (model.getScreenAlignmentSupport() == null) { screenPos = calculateScreenPosition(model.getScreenAlignment(), model); } else { screenPos = calculateScreenPosition(model.getScreenAlignment(), model.getScreenAlignmentSupport(), model); } if (screenPos != null) { group.setPosition(screenPos.x, screenPos.y); } else { float positionMultiplier = resolutionHelper.getPositionMultiplier(); group.setPosition(model.getX() * positionMultiplier, model.getY() * positionMultiplier); } setScaleProperty(model, group); } }
public void resize(float width, float height) { changing(width, height); getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true); if (isStretching) {//拉伸适配的时候,计算一下iphoneX的安全边距 calculationCuts(); calculationAafeArea(1, 1); return; } float bl = getWidth() / getHeight() * Gdx.graphics.getHeight() / Gdx.graphics.getWidth(); if (bl < 1) { cutWidth = (1 - bl) * getWidth() / 2f; cutHeight = 0; getRoot().setScale(bl, 1); getRoot().setPosition(cutWidth, 0); cutWidth = cutWidth / getRoot().getScaleX(); calculationAafeArea(bl, 1); } else if (bl >= 1) { cutWidth = 0; cutHeight = (1 - 1 / bl) * getHeight() / 2f; getRoot().setScale(1, 1 / bl); getRoot().setPosition(0, cutHeight); cutHeight = cutHeight / getRoot().getScaleY(); calculationAafeArea(1, bl); } calculationCuts(); }