You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>This tutorial shows how to add an animation controller and channels, and how to respond to user input by triggering an animation in a loaded model.</p>
1005
+
<p>This tutorial shows how to add an animation controller and how to respond to user input by triggering an animation in a loaded model.</p>
<p>To check this, <bclass="button">RMB</b> select your model and click “Edit in SceneComposer” if the models file extension is .j3o, or “View” if not. You can then see the tree for the model so you can locate the node the control resides in. You can access the subnode with the following code.</p>
<p>In response to a question about animations on different channels interfering with each other, <strong>Nehon</strong>, on the jME forum wrote,</p>
1199
-
</div>
1200
-
<divclass="quoteblock">
1201
-
<blockquote>
1202
-
<divclass="paragraph">
1203
-
<p>You have to consider channels as part of the skeleton that are animated. The default behavior is to use the whole skeleton for a channel.</p>
1204
-
</div>
1205
-
<divclass="paragraph">
1206
-
<p>In your example the first channel plays the walk anim, then the second channel plays the dodge animation.</p>
1207
-
</div>
1208
-
<divclass="paragraph">
1209
-
<p>Arms and feet are probably not affected by the doge animation so you can see the walk anim for them, but the rest of the body plays the dodge animation.</p>
1210
-
</div>
1211
-
<divclass="paragraph">
1212
-
<p>Usually multiple channels are used to animate different part of the body. For example you create one channel for the lower part of the body and one for the upper part. This allow you to play a walk animation with the lower part and for example a shoot animation with the upper part. This way your character can walk while shooting.</p>
1213
-
</div>
1214
-
<divclass="paragraph">
1215
-
<p>In your case, where you want animations to chain for the whole skeleton, you just have to use one channel.</p>
<h2id="responding-to-animation-events"><aclass="anchor" href="#responding-to-animation-events"></a>Responding to Animation Events</h2>
1231
1204
<divclass="sectionbody">
1232
1205
<divclass="paragraph">
1233
-
<p>Add <code>implements AnimEventListener</code> to the class declaration. This interface gives you access to events that notify you when a sequence is done, or when you change from one sequence to another, so you can respond to it. In this example, you reset the character to a standing position after a <code>Walk</code> cycle is done.</p>
1206
+
<p>A Tween (part of an action sequence) can call a method on a class, allowing your application code to be informed of the animation state. In this example, you reset the character to a standing position after a <code>Walk</code> cycle is done.</p>
1234
1207
</div>
1235
1208
<divclass="listingblock">
1236
1209
<divclass="content">
1237
1210
<preclass="highlightjs highlight"><codeclass="language-java hljs" data-lang="java">public class HelloAnimation extends SimpleApplication
* Map the spacebar to the "Walk" input action, and add a listener to initiate
1275
+
* the "advance" animation action each time it's pressed.
1276
+
*/
1277
+
private void initKeys() {
1278
+
inputManager.addMapping("Walk", new KeyTrigger(KeyInput.KEY_SPACE));
1279
+
1280
+
ActionListener handler = new ActionListener() {
1281
+
@Override
1282
+
public void onAction(String name, boolean keyPressed, float tpf) {
1283
+
if (keyPressed && control.getCurrentAction() != advance) {
1284
+
control.setCurrentAction("advance");
1285
+
}
1286
+
}
1287
+
};
1288
+
inputManager.addListener(handler, "Walk");
1289
+
}</code></pre>
1298
1290
</div>
1299
-
<divclass="paragraph">
1300
-
<p>To use the input controller, you need to implement the actionListener by testing for each action by name, then set the channel to the corresponding animation to run.</p>
1301
1291
</div>
1302
1292
<divclass="ulist">
1303
1293
<ul>
1304
1294
<li>
1305
-
<p>The second parameter of setAnim() is the blendTime (how long the current animation should overlap with the last one).</p>
1306
-
</li>
1307
-
<li>
1308
-
<p>LoopMode can be Loop (repeat), Cycle (forward then backward), and DontLoop (only once).</p>
1295
+
<p>By default, the animation will loop, there is an overloaded <code>setCurrentAction</code> method that allows you to set the loop mode.</p>
1309
1296
</li>
1310
1297
<li>
1311
-
<p>If needed, use channel.setSpeed() to set the speed of this animation.</p>
1298
+
<p>If needed, use Action::setSpeed to set the speed of this animation.</p>
1312
1299
</li>
1313
1300
<li>
1314
-
<p>Optionally, use channel.setTime() to Fast-forward or rewind to a certain moment in time of this animation.</p>
1301
+
<p>Optionally, use AnimComposer::.setTime to Fast-forward or rewind to a certain moment in time of this animation.</p>
0 commit comments