瀏覽代碼

Updated BaseAppState section

mitm001 8 年之前
父節點
當前提交
975204dd37
共有 1 個文件被更改,包括 61 次插入1 次删除
  1. 61 1
      src/docs/asciidoc/jme3/advanced/application_states.adoc

+ 61 - 1
src/docs/asciidoc/jme3/advanced/application_states.adoc

@@ -4,6 +4,7 @@
 :revdate: 2016/03/17 20:48
 :relfileprefix: ../../
 :imagesdir: ../..
+:experimental:
 ifdef::env-github,env-browser[:outfilesuffix: .adoc]
 
 
@@ -280,8 +281,67 @@ Notable BaseAppState changes are as follows:
 
 You use BaseAppState no differently than AbstractAppState, other than mentioned above, and which one you use is entirely up to you. However, BaseAppState makes your life easier and is the recommended one to use now.
 
-If you use netbeans or the jme SDK you can add the following template to your IDE.
+If you use the jme SDK you can add the following template to make adding BaseAppState to your project easier. 
 
+*  From the SDK select menu:Tools[Templates>JME Classes>New AppState].
+*  Click the btn:[Duplicate] button.
+*  Rename this newly created copy to "`New BaseAppState`".
+*  Select btn:[Open In Editor].
+*  Select all text in the open file and delete it.
+*  Copy and paste the code below into the file.
 
+[source,java]
+----
+<#assign licenseFirst = "/*">
+<#assign licensePrefix = " * ">
+<#assign licenseLast = " */">
+<#include "../Licenses/license-${project.license}.txt">
+
+<#if package?? && package != "">package ${package};
+</#if>import com.jme3.app.Application;import com.jme3.app.state.BaseAppState;
+
+/** 
+ * 
+ * @author ${user} 
+ */
+public class ${name} extends BaseAppState {        
+    
+    @Override    
+    protected void initialize(Application app) {        
+        //It is technically safe to do all initialization and cleanup in the         
+        //onEnable()/onDisable() methods. Choosing to use initialize() and         
+        //cleanup() for this is a matter of performance specifics for the         
+        //implementor.        
+        //TODO: initialize your AppState, e.g. attach spatials to rootNode    
+    }
+    
+    @Override    
+    protected void cleanup(Application app) {        
+        //TODO: clean up what you initialized in the initialize method,        
+        //e.g. remove all spatials from rootNode    
+    }
+    
+    //onEnable()/onDisable() can be used for managing things that should     
+    //only exist while the state is enabled. Prime examples would be scene     
+    //graph attachment or input listener attachment.    
+    @Override    protected void onEnable() {        
+        //Called when the state is fully enabled, ie: is attached and         
+        //isEnabled() is true or when the setEnabled() status changes after the         
+        //state is attached.    
+    }
+    
+    @Override    
+    protected void onDisable() {        
+        //Called when the state was previously enabled but is now disabled         
+        //either because setEnabled(false) was called or the state is being         
+        //cleaned up.    
+    }        
+    
+    @Override    
+    public void update(float tpf) {        
+        //TODO: implement behavior during runtime    
+    }    
+}
+----
 
 See link:http://javadoc.jmonkeyengine.org/com/jme3/app/state/BaseAppState.htmlBaseAppState for more information.