小编Ess*_*Dee的帖子

如何在libgdx Scene2d的舞台上放大和缩小?

我正在使用libgdx进行2D游戏,并将六角形演员添加到一个组中,然后将其添加到舞台中.对于普通相机,您可以camera.zoom在渲染方法中使用它来放大和缩小以及camera.translate在世界各地进行平移.

我一直在使用舞台使用的相机stage.getCamera(),我仍然可以打电话,stage.getcamera().translate但没有stage.getCamera().zoom选择.

这是我的代码:

//import statements

public class HexGame implements ApplicationListener{

private Stage stage;

private Texture hexTexture;
private Group hexGroup;

private int screenWidth;
private int screenHeight;


@Override
public void create() {

    hexTexture = new Texture(Gdx.files.internal("hex.png"));

    screenHeight = Gdx.graphics.getHeight();
    screenWidth = Gdx.graphics.getWidth();

    stage = new Stage(new ScreenViewport());

    hexGroup = new HexGroup(screenWidth,screenHeight,hexTexture);

    stage.addActor(hexGroup);
}

@Override
public void dispose() {
    stage.dispose();
    hexTexture.dispose();
}

@Override
public void render() {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();

    handleInput();
    stage.getCamera().update();

} …
Run Code Online (Sandbox Code Playgroud)

java android zoom libgdx scene2d

3
推荐指数
1
解决办法
4729
查看次数

Java:当将二维自定义类数组传递给构造函数时,我在数组中丢失了值

我知道标题没有意义,但我想不出如何更好地说话,请耐心等待.

我正在使用java与LibGDX,我正在尝试从保存的像素图加载数据,以在屏幕上呈现地图.在像素图中,每个像素代表六边形的颜色(地图是六边形网格).

问题是:我将数据(特别是颜色)从像素图加载到我称为HexInfo的类的数组中.但是,当我将此数组传递给另一个类以便在我的屏幕上绘制它时,数组中的每个HexInfo项目的颜色都为黑色.以下是一切设置的方法

hexInfo = new HexInfo[cols][rows];

for (int i = 0; i < cols; i++)
            {
                for (int j = 0; j < rows; j++)
                {
                    Color.rgba8888ToColor(color, savedScreenData.getPixel(i, j));

                    hexInfo[i][j] = new HexInfo(i,j);
                    hexInfo[i][j].setColour(color);
                    hexInfo[i][j].setIsVisible(true);
                    hexInfo[i][j].setIsOccupied(true);

                    //It is definitely set because this gives the correct colours
                    System.out.println(hexInfo[i][j].getColour());
                }
            }
mapScreen = new MapScreen(hexInfo);
Run Code Online (Sandbox Code Playgroud)

这里^,屏幕上打印的getColour是正确的.

然后,在MapScreen类中,我为每个hexInfo使用for循环来获取getColour:

public MapScreen(HexInfo[][] hexInfo)
{
cols = hexInfo.length;
    rows = hexInfo[0].length;

    for (int i = 0; i < cols; i++) {
        for (int j = …
Run Code Online (Sandbox Code Playgroud)

java arrays constructor multidimensional-array libgdx

0
推荐指数
1
解决办法
174
查看次数