同じフレームアニメーションの場合巻き戻さないようにする
alkn203 opened this issue · comments
this.rewind = true;
のようなプロパティを追加
gotoAndPlay: function(name) {
if (this.name === name && !this.rewind) return;
this.name = name;
this.frame = 0;
this.currentFrameIndex = 0;
this.currentAnimation = this.ss.getAnimation(name);
this._updateFrame();
this.paused = false;
return this;
},
のようにすれば、キーが押しっぱなしの時でもアニメーションを巻き戻さず継続可能。
@phi-jp よく見ると上のコードだとおかしいですね。すみません。
ややこしく書いてしまいましたが、以下のサンプルではキーボード操作した時にスケート状態になります。
これを回避するためには、現状ではユーザー側でアニメーション名を別途変数に入れてgotoAndPlayを重複して呼ばないように制御したりする必要があるのですが、これがライブラリ側で上手く対処できたらいいな~という話ですw
http://runstant.com/alkn203/projects/6f4eb0f2
@phi-jp @alkn203
雑ですが、
http://runstant.com/simiraaaa/projects/2326c483
アニメーションが同じ時に切り替えないチェックをしています。
currentAnimationNameというプロパティがあると良いかもしれません
rewindはオブジェクトに持たせるよりはメソッドの引数のほうが最適なような気がします。
gotoAndPlay(name, keep) {
if(keep && name === this.currentAnimationName) return this;
}
@simiraaaa オブジェクトごと比較とは思いつかなかったですw
修正ありがとうございます。確かに引数でその都度指定の方が良いですね。
以下の感じでしょうか。
http://runstant.com/alkn203/projects/13ddc7d1
@phi-jp もしよろしければプルレクしたいと思います。
@alkn203 @simiraaaa 遅くなりましたmm
理解しましたb
そもそも keep も必要なく必ず this.currentAnimationName === name
で弾くようにしちゃって良いかなと思ってるんですがどうでしょう?
いいと思いますが、逆に同じアニメーションを指定しても最初から始められなくなるので、第二引数で何かしら指定できた方が良いとは思います。
@alkn203 @simiraaaa では keep のデフォルト値を true の方向で!!
b
理解不足があって少し手こずってましたw
以下でいけると思います。準備出来次第、プルレクします。
gotoAndPlay: function(name, keep) {
keep = (keep !== undefined) ? keep : true;
if (keep && name === this.currentAnimationName
&& this.currentFrameIndex < this.currentAnimation.frames.length) {
return this;
}
this.currentAnimationName = name;
マージして頂けたのでクローズします。
ありがとうございました!
肝心な
this.currentAnimationName = name;
が抜けてましたw
あと、gotoAndStopからの流れの時は無条件に
巻き戻すようにしています。
gotoAndPlay: function(name, keep) {
keep = (keep !== undefined) ? keep : true;
if (keep && name === this.currentAnimationName
&& this.currentFrameIndex < this.currentAnimation.frames.length
&& !this.paused) {
return this;
}
this.currentAnimationName = name;
this.frame = 0;
this.currentFrameIndex = 0;
this.currentAnimation = this.ss.getAnimation(name);
this._updateFrame();
this.paused = false;
return this;
},
gotoAndStop: function(name) {
this.currentAnimationName = name;
this.frame = 0;
this.currentFrameIndex = 0;
this.currentAnimation = this.ss.getAnimation(name);
this._updateFrame();
this.paused = true;
return this;
},
マージ済み