我几乎尝试了一切,但我仍然无法理解这一点。我正在使用以下方法之一加载底部广告时更改actor的高度和y:setPosition + setSize,setY + setHeight和setBounds。几乎每次(10次7次)高度变化但位置不是(!)。我使用adListener在我的Game类中调用onAdLoad方法,该方法在Screen中调用onAdLoad方法。我放置了Gdx.app.log,它在onAdLoad(Screen)方法的末尾写入了actor的y坐标,它写了正确的新y,但是当我从render方法写y坐标时,它是0.请帮我此
一些代码:
AndroidLauncher类onCreate方法:
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Gdx.app.log("AdView:", "AdLoaded");
if (adView.getVisibility() == View.VISIBLE)
game.onAdLoad(adView.getHeight());
}
});
游戏课程:
public void onAdLoad(int adHeight) {
adsHeight = adHeight;
MyScreen activeScreen = ((MyScreen) getScreen());
if (activeScreen != null) {
activeScreen.onAdLoad();
}
}
MyScreen界面:
public interface MyScreen extends Screen {
void onAdLoad();
}
和其中一个屏幕:
private Table mainMenu;
@Override
public void onAdLoad() {
float adsHeight = MyGdxGame.adsHeight;
// mainMenu.setBounds(0, adsHeight, Gdx.graphics.getWidth(),Gdx.graphics.getHeight() - adsHeight);
Gdx.app.log("onAdLoad",adsHeight+"");
mainMenu.setHeight(Gdx.graphics.getHeight() - adsHeight);
mainMenu.setY(adsHeight);
Gdx.app.log("onAdLoad", mainMenu.getY() + "");
// mainMenu.setPosition(0, adsHeight);
// mainMenu.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - adsHeight);
// mainMenu.layout();
}
UPD:这也不行:
public void onAdLoad() {
//...
stage.getActors().clear();
stage.addActor(mainMenu);
}