Skip to content

Commit

Permalink
Merge pull request #66 from soltycabbage/feature/bug-fix2
Browse files Browse the repository at this point in the history
たまに自分の位置が他人から見た位置と異なることがあるのを修正
  • Loading branch information
nise-nabe committed Jan 29, 2014
2 parents 2cce593 + 686088e commit fc71f65
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
30 changes: 30 additions & 0 deletions public/js/src/entity/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},

/**
* 死にモーション
*/
Expand Down
21 changes: 3 additions & 18 deletions public/js/src/entityManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
},

Expand Down

0 comments on commit fc71f65

Please sign in to comment.