|
@@ -152,3 +152,37 @@ public class MyControl extends AbstractControl implements Savable, Cloneable {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
----
|
|
----
|
|
|
|
+
|
|
|
|
+See also:
|
|
|
|
+
|
|
|
|
+* To learn more about `write()` and `read()`, see <<jme3/advanced/save_and_load#,Save and Load>>
|
|
|
|
+* To learn more about `setUserData()`, see <<jme3/advanced/spatial#,Spatial>>.
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+== The Control Interface
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+[TIP]
|
|
|
|
+====
|
|
|
|
+In the less common case that you want to create a Control that also extends another class, create a custom interface that extends jME3's Control interface. Your class can become a Control by implementing the Control interface, and at the same time extending another class.
|
|
|
|
+====
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+The Control interface can be found under `com.jme3.scene.control.Control`. It has the following method signatures:
|
|
|
|
+
|
|
|
|
+* `cloneForSpatial(Spatial)`: Clones the Control and attaches it to a clone of the given Spatial. +
|
|
|
|
+Implement this method to be able to <<jme3/advanced/save_and_load#,save() and load()>> Spatials carrying this Control. +
|
|
|
|
+The AssetManager also uses this method if the same spatial is loaded twice. You can specify which fields you want your object to reuse (e.g. collisionshapes) in this case.
|
|
|
|
+* `setEnabled(boolean)`: Toggles a boolean that enables or disables the Control. Goes with accessor `isEnabled();`. You test for it in the `update(float tpf)` loop before you execute anything.
|
|
|
|
+* There are also some internal methods that you do not call from user code: `setSpatial(Spatial s)`, `update(float tpf);`, `render(RenderManager rm, ViewPort vp)`.
|
|
|
|
+
|
|
|
|
+Usage example:
|
|
|
|
+
|
|
|
|
+. Create a custom control interface.
|
|
|
|
++
|
|
|
|
+[source,java]
|
|
|
|
+----
|
|
|
|
+public interface MyControlInterface extends Control {
|
|
|
|
+ public void setSomething(int x); // optionally, add custom methods
|
|
|
|
+}
|
|
|
|
+----
|