File tree Expand file tree Collapse file tree 2 files changed +12
-20
lines changed Expand file tree Collapse file tree 2 files changed +12
-20
lines changed Original file line number Diff line number Diff line change @@ -79,15 +79,12 @@ KeyboardControls.prototype.initialize = function() {
79
79
this .app .keyboard .on (pc .EVENT_KEYUP , this .keyUp , this );
80
80
};
81
81
82
-
83
- KeyboardControls .prototype .keyDown = function (e ) {
84
- if ((e .key === pc .KEY_P ) && (this .entity .anim .baseLayer .activeState !== ' Punch' )) {
82
+ KeyboardControls .prototype .update = function (dt ) {
83
+ if (this .app .keyboard .wasPressed (pc .KEY_P ) && (this .entity .anim .baseLayer .activeState !== ' Punch' )) {
85
84
this .entity .anim .setBoolean (' punch' , true );
86
85
}
87
- };
88
86
89
- KeyboardControls .prototype .keyUp = function (e ) {
90
- if ((e .key === pc .KEY_P ) && (this .entity .anim .baseLayer .activeState === ' Punch' )) {
87
+ if (this .app .keyboard .wasReleased (pc .KEY_P ) && (this .entity .anim .baseLayer .activeState === ' Punch' )) {
91
88
this .entity .anim .setBoolean (' punch' , false );
92
89
}
93
90
};
Original file line number Diff line number Diff line change @@ -48,9 +48,16 @@ AnimationBlending.prototype.initialize = function() {
48
48
this .blendTime = 0.2 ;
49
49
50
50
this .setState (' idle' );
51
+ };
52
+
53
+ AnimationBlending .prototype .update = function (dt ) {
54
+ if (this .app .keyboard .wasPressed (pc .KEY_P )) {
55
+ this .setState (' punch' );
56
+ }
51
57
52
- this .app .keyboard .on (pc .EVENT_KEYDOWN , this .keyDown , this );
53
- this .app .keyboard .on (pc .EVENT_KEYUP , this .keyUp , this );
58
+ if (this .app .keyboard .wasReleased (pc .KEY_P )) {
59
+ this .setState (' idle' );
60
+ }
54
61
};
55
62
56
63
AnimationBlending .prototype .setState = function (state ) {
@@ -61,18 +68,6 @@ AnimationBlending.prototype.setState = function (state) {
61
68
// the current animation state to the start of the target animation.
62
69
this .entity .animation .play (states[state].animation , this .blendTime );
63
70
};
64
-
65
- AnimationBlending .prototype .keyDown = function (e ) {
66
- if ((e .key === pc .KEY_P ) && (this .state !== ' punch' )) {
67
- this .setState (' punch' );
68
- }
69
- };
70
-
71
- AnimationBlending .prototype .keyUp = function (e ) {
72
- if ((e .key === pc .KEY_P ) && (this .state === ' punch' )) {
73
- this .setState (' idle' );
74
- }
75
- };
76
71
```
77
72
78
73
From this point, you are able to add more and more animations to the animation component and start scripting much more complex animation state charts.
You can’t perform that action at this time.
0 commit comments