ページ 1 / 1
解決)マップ画面タッチでの0.5刻み瞬間移動
Posted: 2022年11月23日(水) 15:09
by こめかみ
"マップ画面内のタッチした場所にプレイヤーが瞬間移動する"
という場合に
コード: 全て選択
this.locate($gameMap.canvasToMapX(TouchInput.x),$gameMap.canvasToMapY(TouchInput.y))
上記の方法で行っているのですが、これを半歩対応(0.5刻み)で行いたいです。
スクリプトで計算できる方法はありますでしょうか?
※トリアコンタン様の半歩移動プラグインを使用し、this.locate()で0.5刻みで瞬間移動できる事は確認済みです。
Re: マップ画面タッチでの0.5刻み瞬間移動
Posted: 2022年11月23日(水) 15:42
by Plasma Dark
canvasToMapX, canvasToMapY の結果を0.5刻みで取得するようなメソッドを定義して、それを使うようにするのが手っ取り早そうです。
コード: 全て選択
(() => {
'use strict';
function Game_Map_HalfLocateMixIn(gameMap) {
gameMap.canvasToMapXHalf = function (x) {
const tileWidth = this.tileWidth();
const originX = this._displayX * tileWidth;
const mapX = Math.floor(2 * (originX + x) / tileWidth);
return this.roundX(mapX)/2;
};
gameMap.canvasToMapYHalf = function (y) {
const tileHeight = this.tileHeight();
const originY = this._displayY * tileHeight;
const mapY = Math.floor(2 * (originY + y) / tileHeight);
return this.roundY(mapY) / 2;
};
}
Game_Map_HalfLocateMixIn(Game_Map.prototype);
})();
こんな感じのプラグインを書けば、 $gameMap.canvasToMapXHalf などとして利用できます。
Re: マップ画面タッチでの0.5刻み瞬間移動
Posted: 2022年11月23日(水) 16:12
by こめかみ
Plasma Dark様
ご回答ありがとうございます。
記載いただいたプラグインにて無事実装できました!(そのままコピペでいけたのですね、大変失礼いたしました)
想定通りの挙動を取る事ができました、ありがとうございます!
Plasma Dark さんが書きました:canvasToMapX, canvasToMapY の結果を0.5刻みで取得するようなメソッドを定義して、それを使うようにするのが手っ取り早そうです。
コード: 全て選択
(() => {
'use strict';
function Game_Map_HalfLocateMixIn(gameMap) {
gameMap.canvasToMapXHalf = function (x) {
const tileWidth = this.tileWidth();
const originX = this._displayX * tileWidth;
const mapX = Math.floor(2 * (originX + x) / tileWidth);
return this.roundX(mapX)/2;
};
gameMap.canvasToMapYHalf = function (y) {
const tileHeight = this.tileHeight();
const originY = this._displayY * tileHeight;
const mapY = Math.floor(2 * (originY + y) / tileHeight);
return this.roundY(mapY) / 2;
};
}
Game_Map_HalfLocateMixIn(Game_Map.prototype);
})();
こんな感じのプラグインを書けば、 $gameMap.canvasToMapXHalf などとして利用できます。