java棋盘网格边距_java – libGDX:为棋盘游戏创建网格

Sprite square = new Sprite(new Texture("texture"));

给予

float squareWidth = camera.viewportWidth / squaresOnWidth;

float squareHeight = camera.viewportHeight / squaresOnHeight;

square.setWidth(squareWidth);

square.setHeight(squareHeight);

batch.begin(); `

for(int y = 0; y < squaresOnHeight; y++){

for(int x = 0; x < squaresOnWidth; x++){

square.setX(x * squareWidth);

square.setY(y * squareHeight);

square.draw(batch);

}

}

batch.end();

这应该输出纹理网格,而不是测试.

如果你想要按钮中的网格.

OrthoGraphicCamera camera = new OrthoGraphicCamera();

camera.setToOrtho(false, yourViewportWidth, yourViewportHeight);

camera.translate(xPos, yPos);

Stage stage = new Stage(your wanted stage width, your wanted stage height, false, batch);

stage.setCamera(camera);

for(int y = 0; y < buttonsOnHeight; y++){

for(int x = 0; x < buttonsOnWidth; x++){

stage.addActor(new TextButton("" + x + y * buttonsOnWidth, textButtonStyle);

}

}

渲染

float buttonWidth = camera.viewportWidth / buttonsOnWidth;

float buttonHeight = camera.viewportHeight / buttonsOnHeight;

for(int y = 0; y < buttonsOnHeight; y++){

for(int x = 0; x < buttonsOnWidth; x++){

TextButton button = stage.getActors().get(x + y * buttonsOnWidth);

button.setX(x * buttonWidth);

button.setY(y * buttonHeight);

button.setWidth(buttonWidth);

button.setHeight(buttonHeight);

}

}

然后绘制舞台,注意你应该停止当前正在运行的任何批处理因为stage拥有它自己的batch.begin()和batch.end().您可以在stage.draw()之后再次启动批处理;

stage.act(delta);

stage.draw();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值