Okay, I’m not entirely sure where this went/what the issue was, so that’s why it’s under general. What’s happening is when I start my game, if start it by attaching the LevelState straight to the stateManager, everything’s fine. But if I attach a MainMenuState first, and then attach LevelState with the “START” button is pressed, a black square appears in every single rigidbody, right at it’s center. Here are pics to understand what’s going on:
Now, first of all, what do you think is causing this? The texture? Some weird camera angle? I have no clue where to begin looking for this bugging.
Here are the two states (only relevant code pasted)
MainMenuState:
[java]
@Override
public void initialize(final AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
this.stateManager = stateManager;
this.app = (SimpleApplication)app;
this.rootNode = this.app.getRootNode();
this.guiNode = this.app.getGuiNode();
start_button = new ButtonAdapter(screen,"start", new Vector2f(0, 0)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
stateManager.detach(stateManager.getState(MainMenuState.class));
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
};
start_button.setPosition(screen.getWidth()/2f-start_button.getWidth()/2f,screen.getHeight()/2f);
start_button.setText("Start");
screen.addElement(start_button);
credits_button = new ButtonAdapter(screen,"credits", new Vector2f(0, 0)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
stateManager.detach(stateManager.getState(MainMenuState.class));
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
};
credits_button.setText("Credits");
credits_button.setPosition(screen.getWidth()/2f-credits_button.getWidth()/2f,screen.getHeight()/2f + start_button.getHeight()+ 5);
screen.addElement(credits_button);
app.getInputManager().setCursorVisible(true);
//TODO: initialize your AppState, e.g. attach spatials to rootNode
//this is called on the OpenGL thread after the AppState has been attached
}
@Override
public void cleanup() {
super.cleanup();
screen.removeElement(credits_button);
screen.removeElement(start_button);
LevelState level_state = new LevelState(screen);
stateManager.attach(level_state);
//screen.r
//guiNode.detachAllChildren();
//TODO: clean up what you initialized in the initialize method,
//e.g. remove all spatials from rootNode
//this is called on the OpenGL thread after the AppState has been detached
}[/java]
LevelState:
[java]@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
System.out.println(app);
this.app = (SimpleApplication)app;
this.stateManager = stateManager;
this.assetManager = this.app.getAssetManager();
this.cam = this.app.getCamera();
this.rootNode = this.app.getRootNode();
this.guiNode = this.app.getGuiNode();
this.bas = this.stateManager.getState(BulletAppState.class);
System.out.println(guiNode.getControl(Screen.class));
generalSetup();
setupPlayer();
//createMappings();
rxf = new ReadXMLFile("assets/Textures/testMap2.tmx",assetManager,bas);
rxf.parse();
l = rxf.createLevel(cam);
rootNode.attachChild(l);
setupCollidables();
createMappings();
game_timer = new LwjglTimer();
Element time_info_l = new Element(screen, "label",new Vector2f(0,0),new Vector2f(190,0),
new Vector4f(5,5,5,5),null);
//Label time_info_l = new Label(screen,"label", new Vector2f(0,0),new Vector2f(190,0));
time_info_l.setPosition(cam.getWidth()/2f - time_info_l.getWidth()/2f, 10f);
time_info_l.setText("Seconds since start:");
time_info_l.setFontColor(ColorRGBA.White);
time_info_l.setFontSize(Math.abs(tlratio) * 15);
time_l = new Label(screen, "time", new Vector2f(0,0),new Vector2f(70,0));
time_l.setPosition(time_info_l.getPosition().x + time_info_l.getWidth(),10f);
time_l.setFontColor(ColorRGBA.White);
time_l.setFontSize(Math.abs(tlratio) * 15);
Effect effect = new Effect(
Effect.EffectType.FadeIn, // The type of effect to use
Effect.EffectEvent.Show, // The event that the effect is associated with
10f // The duration of time over which the effect executes (2.2 seconds)
);
time_info_l.addEffect(effect);
time_info_l.hide();
///screen.getEffectManager().applyEffect(effect);
screen.addElement(time_l);
screen.addElement(time_info_l);
time_info_l.showWithEffect();
//TODO: initialize your AppState, e.g. attach spatials to rootNode
//this is called on the OpenGL thread after the AppState has been attached
}[/java]
If you really want the code from the other functions, I’ll post it. I just don’t think they play a role in this. I’ve tried making the MainMenuState immediately switch to the LevelState after being called (and not do any of the GUI stuff) and the issue still occurs.