At end of Button constructor, i have a set bound box, that run bad, because with this line decomenteds i only can see a blank screen (really, see the buttons only 0.5 sec aprox only) later all black,
why? and why also in other no-buttons objects as bckgQuad of MainMenuState?
Thanks
MainMenuState.java
package gamestates;
import ui.Button;
import com.jme.image.Texture;
import com.jme.input.MouseInput;
import com.jme.math.Vector3f;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.RenderState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jmex.game.state.BasicGameState;
public class MainMenuState extends BasicGameState {
private Quad bckgQuad;
private Button newButton;
private Button quitButton;
private Button creditsButton;
public MainMenuState() {
super("mainMenuState");
// Build our menu
this.buildMenu();
}
private void buildMenu() {
// Create BlendState
DisplaySystem display = DisplaySystem.getDisplaySystem();
BlendState bs = display.getRenderer().createBlendState();
bs.setBlendEnabled(true);
bs.setSourceFunction(BlendState.SourceFunction.SourceAlpha );
bs.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
// Create background quad
Texture t = TextureManager.loadTexture(
MainMenuState.class.getClassLoader().getResource("res/menu_bckg2.png"),
Texture.MinificationFilter.Trilinear,
Texture.MagnificationFilter.Bilinear);
this.bckgQuad = new Quad("bckgQuad", 1024, 768);
this.bckgQuad.setRenderQueueMode(Renderer.QUEUE_ORTHO);
this.bckgQuad.setLocalTranslation(512, 300, 0);
TextureState ts = display.getRenderer().createTextureState();
ts.setTexture(t);
this.bckgQuad.setRenderState(ts);
// Create buttons
this.newButton = new Button("newButton", 256, 256, "res/new0.png", "res/new1.png");
this.quitButton = new Button("quitButton", 256, 256, "res/quit0.png", "res/quit1.png");
this.creditsButton = new Button("creditsButton", 256, 256, "res/credits0.png", "res/credits1.png");
// Apply BlendState
this.newButton.setRenderState(bs);
this.quitButton.setRenderState(bs);
this.creditsButton.setRenderState(bs);
// Set position
this.newButton.setLocalTranslation(860, 250, 0);
this.quitButton.setLocalTranslation(600, 420, 0);
this.creditsButton.setLocalTranslation(300, 170, 0);
// Attach all
this.getRootNode().attachChild(this.bckgQuad);
this.getRootNode().attachChild(this.newButton);
this.getRootNode().attachChild(this.quitButton);
this.getRootNode().attachChild(this.creditsButton);
this.getRootNode().updateRenderState();
}
public void update(float tpf) {
super.update(tpf);
System.out.println("UPD");
}
}
Button.java
package ui;
import com.jme.renderer.Renderer;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.RenderState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
public class Button extends Quad {
private Texture idleTexture;
private Texture focusTexture;
private boolean focus;
public Button(String name, int width, int height,
String idleTextureFn, String focusTextureFn) {
super(name, width, height);
DisplaySystem display = DisplaySystem.getDisplaySystem();
this.setRenderQueueMode(Renderer.QUEUE_ORTHO);
// Load TextureStates and Textures
this.idleTexture = TextureManager.loadTexture(
Button.class.getClassLoader().getResource(idleTextureFn),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
this.focusTexture = TextureManager.loadTexture(
Button.class.getClassLoader().getResource(focusTextureFn),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
TextureState ts = display.getRenderer().createTextureState();
this.setRenderState(ts);
// BoundingBox for collition
//this.setModelBound(new BoundingBox());
//this.updateModelBound();
this.setFocus(true);
}
public void setFocus(boolean value) {
if (value == true) {
TextureState ts = this.getRenderState(RenderState.RS_TEXTURE);
ts.setTexture(this.focusTexture);
} else if (value == false) {
TextureState ts = this.getRenderState(RenderState.RS_TEXTURE);
ts.setTexture(this.idleTexture);
}
this.focus = value;
this.updateRenderState();
}
}