diff --git a/public/js/src/entity/entity.js b/public/js/src/entity/entity.js index e477d05..9feb6fb 100644 --- a/public/js/src/entity/entity.js +++ b/public/js/src/entity/entity.js @@ -81,6 +81,36 @@ bq.entity.Entity = cc.Sprite.extend({ bq.baseLayer.addChild(label, bq.config.tags.EXP_LABEL); }, + /** + * 指定位置に移動する + * @param {cc.p} pos + */ + moveTo: function(pos) { + var moveActTag = 'entity_move_' + this.name; + var move = cc.MoveTo.create(0.2, pos); + if (this.currentState == bq.entity.EntityState.Mode.walking) { + var runningMoveAct = this.getActionByTag(moveActTag); + if (runningMoveAct) { + this.stopAction(runningMoveAct); + delete runningMoveAct; + } + + // 走ってる状態だったら移動だけ(アニメーションは更新しない) + move.setTag(moveActTag); + this.runAction(move); + } else { + this.updateAnimation(bq.entity.EntityState.Mode.walking, null); + // 移動したあと急に止めるとアニメーションが不自然になるので少し遅延を入れる + var delay = cc.DelayTime.create(0.2); + var changeAnime = cc.CallFunc.create(function () { + this.updateAnimation(bq.entity.EntityState.Mode.stop, null) + }.bind(this)); + + var act = cc.Sequence.create([move, delay, changeAnime]); + this.runAction(act); + } + }, + /** * 死にモーション */ diff --git a/public/js/src/entityManager.js b/public/js/src/entityManager.js index 66ca2d8..da86818 100644 --- a/public/js/src/entityManager.js +++ b/public/js/src/entityManager.js @@ -57,26 +57,11 @@ bq.EntityManager = cc.Class.extend({ * @param {bq.model.PlayerMove} moveData */ moveTo: function(moveData) { - if (!this.otherPlayers_[moveData.userId]) { + var otherPlayer = this.otherPlayers_[moveData.userId]; + if (!otherPlayer) { this.createOtherPlayer(moveData); } else { - var otherPlayer = this.otherPlayers_[moveData.userId]; - var move = cc.MoveTo.create(0.2, cc.p(moveData.x, moveData.y)); - - if (otherPlayer.currentState == bq.entity.EntityState.Mode.walking) { - // 走ってる状態だったら移動だけ(アニメーションは更新しない) - otherPlayer.runAction(move); - } else { - otherPlayer.updateAnimation(bq.entity.EntityState.Mode.walking, null); - // 移動したあと急に止めるとアニメーションが不自然になるので少し遅延を入れる - var delay = cc.DelayTime.create(0.2); - var changeAnime = cc.CallFunc.create(function () { - otherPlayer.updateAnimation(bq.entity.EntityState.Mode.stop, null) - }); - - var act = cc.Sequence.create([move, delay, changeAnime]); - otherPlayer.runAction(act); - } + otherPlayer.moveTo(cc.p(moveData.x, moveData.y)); } },