本文整理了Java中com.badlogic.gdx.scenes.scene2d.Stage.getCamera()
方法的一些代码示例,展示了Stage.getCamera()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stage.getCamera()
方法的具体详情如下:
包路径:com.badlogic.gdx.scenes.scene2d.Stage
类名称:Stage
方法名:getCamera
[英]The viewport's camera.
[中]视口的摄影机。
代码示例来源:origin: libgdx/libgdx
@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);
}
代码示例来源:origin: libgdx/libgdx
Camera cam = stage.getCamera();
batch.setProjectionMatrix(cam.combined);
batch.begin();
代码示例来源:origin: libgdx/libgdx
float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight();
boolean below = true;
if (height > heightBelow) {
代码示例来源:origin: libgdx/libgdx
float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight();
boolean below = true;
if (height > heightBelow) {
代码示例来源:origin: libgdx/libgdx
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());
}
}
代码示例来源:origin: libgdx/libgdx
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());
}
}
代码示例来源:origin: libgdx/libgdx
public void create () {
stage = new Stage();
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
label = new Label("", skin);
Table root = new Table(skin);
root.setFillParent(true);
root.setBackground(skin.getDrawable("default-pane"));
root.debug().defaults().space(6);
root.add(new TextButton("Button 1", skin));
root.add(new TextButton("Button 2", skin)).row();
root.add("Press spacebar to change the viewport:").colspan(2).row();
root.add(label).colspan(2);
stage.addActor(root);
viewports = getViewports(stage.getCamera());
names = getViewportNames();
stage.setViewport(viewports.first());
label.setText(names.first());
Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {
public boolean keyDown (int keycode) {
if (keycode == Input.Keys.SPACE) {
int index = (viewports.indexOf(stage.getViewport(), true) + 1) % viewports.size;
label.setText(names.get(index));
Viewport viewport = viewports.get(index);
stage.setViewport(viewport);
resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
return false;
}
}, stage));
}
代码示例来源:origin: libgdx/libgdx
stage1.getCamera().position.set(100, 100, 0);
代码示例来源:origin: bladecoder/bladecoder-adventure-engine
public void show() {
if (!isVisible()) {
resize((int) getStage().getCamera().viewportWidth, (int) getStage().getCamera().viewportHeight);
setVisible(true);
setPosition(orgPos.x, orgPos.y);
addAction(Actions.moveTo(targetPos.x, targetPos.y, .1f));
}
}
代码示例来源:origin: peakgames/libgdx-stagebuilder
@Override
public void render(float delta) {
super.render(delta);
debugRenderer.setProjectionMatrix(stage.getCamera().combined);
debugRenderer.begin(ShapeRenderer.ShapeType.Line);
debugRenderer.setColor(Color.YELLOW);
Vector2 gameAreaBounds = game.getResolutionHelper().getGameAreaBounds();
Vector2 gameAreaPosition= game.getResolutionHelper().getGameAreaPosition();
debugRenderer.rect(gameAreaPosition.x, gameAreaPosition.y, gameAreaBounds.x, gameAreaBounds.y);
debugRenderer.rect(gameAreaPosition.x+1, gameAreaPosition.y+1, gameAreaBounds.x-2, gameAreaBounds.y-2);
debugRenderer.end();
}
代码示例来源:origin: moribitotech/MTX
stage.getCamera().position.set(AppSettings.SCREEN_W / 2,
AppSettings.SCREEN_H / 2, 0);
代码示例来源:origin: bladecoder/bladecoder-adventure-engine
float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight();
boolean below = true;
if (height > heightBelow) {
代码示例来源:origin: BrentAureli/SuperMario
@Override
public void render(float delta) {
//separate our update logic from render
update(delta);
//Clear the game screen with Black
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//render our game map
renderer.render();
//renderer our Box2DDebugLines
b2dr.render(world, gamecam.combined);
game.batch.setProjectionMatrix(gamecam.combined);
game.batch.begin();
player.draw(game.batch);
for (Enemy enemy : creator.getEnemies())
enemy.draw(game.batch);
for (Item item : items)
item.draw(game.batch);
game.batch.end();
//Set our batch to now draw what the Hud camera sees.
game.batch.setProjectionMatrix(hud.stage.getCamera().combined);
hud.stage.draw();
if(gameOver()){
game.setScreen(new GameOverScreen(game));
dispose();
}
}
代码示例来源:origin: com.badlogicgames.gdx/gdx
float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight();
boolean below = true;
if (height > heightBelow) {
代码示例来源:origin: com.badlogicgames.gdx/gdx
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());
}
}
代码示例来源:origin: com.github.xaguzman/gamedevlib-libgdx
void keepWithinStage () {
if (!keepWithinStage) return;
Stage stage = getStage();
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());
}
}
代码示例来源:origin: kotcrab/vis-ui
/**
* Makes sures that actor will be fully visible in stage. If it's necessary actor position will be changed to fit it
* on screen.
*/
public static void keepWithinStage (Stage stage, Actor actor) {
//taken from scene2d.ui Window
Camera camera = stage.getCamera();
if (camera instanceof OrthographicCamera) {
OrthographicCamera orthographicCamera = (OrthographicCamera) camera;
float parentWidth = stage.getWidth();
float parentHeight = stage.getHeight();
if (actor.getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom)
actor.setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, actor.getY(Align.right), Align.right);
if (actor.getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom)
actor.setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, actor.getY(Align.left), Align.left);
if (actor.getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom)
actor.setPosition(actor.getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top);
if (actor.getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom)
actor.setPosition(actor.getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom);
} else if (actor.getParent() == stage.getRoot()) {
float parentWidth = stage.getWidth();
float parentHeight = stage.getHeight();
if (actor.getX() < 0) actor.setX(0);
if (actor.getRight() > parentWidth) actor.setX(parentWidth - actor.getWidth());
if (actor.getY() < 0) actor.setY(0);
if (actor.getTop() > parentHeight) actor.setY(parentHeight - actor.getHeight());
}
}
}
代码示例来源:origin: langurmonkey/gaiasky
Camera camera = stage.getCamera();
if (camera instanceof OrthographicCamera) {
OrthographicCamera orthographicCamera = (OrthographicCamera) camera;
内容来源于网络,如有侵权,请联系作者删除!