<BaseGame | User's Guide | StandardGame>
SimpleGame provides almost all of the functionality needed to get a simple game running. It is designed for quick usage and easy prototyping. It provides basic first-person look and move actions as well as many debug options including things like screenshots, render statistics monitoring, and bounding box drawing. There is an automatically rendered root scene node (rootNode) that all game data can be attached to. Most jME demos use the SimpleGame type.
Note: the basic game loop is inherited from BaseGame, but all of the methods are implemented and provide additional functionality.
Additional information about the game loop implementation is provided below:
The following actions are performed in this method by default (some minor details are omitted for clarity):
display member variable.cam member variable.input member variable.timer member variable.The following actions are performed in this method by default (some minor details are omitted for clarity):
- Finish this description
- Finish this description
SimpleGame creates an input system that detects the following keys:
| Key | Action |
|---|---|
| W | Move Forward |
| A | Strafe Left |
| S | Move Backward |
| D | Strafe Right |
| Up | Look Up |
| Down | Look Down |
| Left | Look Left |
| Right | Look Right |
| T | Wireframe Mode on/off |
| P | Pause On/Off |
| L | Lights On/Off |
| C | Print Camera Position |
| B | Bounding Volumes On/Off |
| N | Normals On/Off |
| F1 | Take Screenshot |
See the Javadoc for more details.
Note - This is from jmetest.renderer.TestSphere. Since AplhaState Class Does Not exists Anymore, THis Change was made afor the use of BlendState Class.
//required import statements import java.io.File; import java.net.URL; import java.util.logging.Logger; import com.jme.app.SimpleGame; import com.jme.bounding.BoundingBox; import com.jme.image.Texture; import com.jme.math.Quaternion; import com.jme.math.Vector3f; import com.jme.scene.state.BlendState; import com.jme.scene.shape.Sphere; //import com.jme.scene.state.AlphaState; import com.jme.scene.state.TextureState; import com.jme.util.TextureManager; import com.jme.util.resource.MultiFormatResourceLocator; import com.jme.util.resource.ResourceLocatorTool; /** * TestSphere extends SimpleGame giving us a basic framework. */ public class TestSphere extends SimpleGame { private static final Logger logger = Logger.getLogger(TestSphere.class .getName()); //required values for rotating the sphere private Quaternion rotQuat = new Quaternion(); private float angle = 0; private Vector3f axis = new Vector3f(1, 1, 0); //the Sphere to render private Sphere s; /** * Entry point for the test, * @param args */ public static void main(String[] args) { TestSphere app = new TestSphere(); //app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG); app.setConfigShowMode(ConfigShowMode.AlwaysShow); app.start(); } /** * updates an angle and applies it to a quaternion * to rotate the Sphere. */ @Override protected void simpleUpdate() { if (tpf < 1) { angle = angle + (tpf * 1); if (angle > 360) { angle = 0; } } rotQuat.fromAngleAxis(angle, axis); s.setLocalRotation(rotQuat); } /** * builds the Sphere and applies the Monkey texture. */ protected void simpleInitGame() { display.setTitle("jME - Sphere"); s = new Sphere("Sphere", 63, 50, 25); s.setLocalTranslation(new Vector3f(0,0,-40)); s.setModelBound(new BoundingBox()); s.updateModelBound(); rootNode.attachChild(s); try { MultiFormatResourceLocator loc2 = new MultiFormatResourceLocator(new File("c:/").toURI(), ".jpg", ".png", ".tga"); ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, loc2); } catch (Exception e) { e.printStackTrace(); } URL u = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "/model/grass.gif"); System.err.println("FOUND URL: "+u); TextureState ts = display.getRenderer().createTextureState(); ts.setEnabled(true); /*ts.setTexture( TextureManager.loadTexture(u,Texture.Trilinear, Texture.Bilinear));*/ ts.setTexture(TextureManager.loadTexture(u, Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear)); rootNode.setRenderState(ts); BlendState blend = display.getRenderer().createBlendState(); blend.setBlendEnabled(true); blend.setSourceFunction(BlendState.SourceFunction.SourceAlpha); blend.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha); blend.setTestEnabled(true); blend.setTestFunction(BlendState.TestFunction.GreaterThan); blend.setEnabled(true); rootNode.setRenderState(blend); } }
<BaseGame | User's Guide | StandardGame>