解決)マップ画面タッチでの0.5刻み瞬間移動

返信する
アバター
こめかみ
記事: 112
登録日時: 2017年9月06日(水) 19:34
連絡する:

解決)マップ画面タッチでの0.5刻み瞬間移動

投稿記事 by こめかみ »

"マップ画面内のタッチした場所にプレイヤーが瞬間移動する"
という場合に

コード: 全て選択

this.locate($gameMap.canvasToMapX(TouchInput.x),$gameMap.canvasToMapY(TouchInput.y))
上記の方法で行っているのですが、これを半歩対応(0.5刻み)で行いたいです。

スクリプトで計算できる方法はありますでしょうか?

※トリアコンタン様の半歩移動プラグインを使用し、this.locate()で0.5刻みで瞬間移動できる事は確認済みです。
最後に編集したユーザー こめかみ [ 2022年11月23日(水) 16:12 ], 累計 1 回
アバター
Plasma Dark
記事: 736
登録日時: 2020年2月08日(土) 02:29
連絡する:

Re: マップ画面タッチでの0.5刻み瞬間移動

投稿記事 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 などとして利用できます。
アバター
こめかみ
記事: 112
登録日時: 2017年9月06日(水) 19:34
連絡する:

Re: マップ画面タッチでの0.5刻み瞬間移動

投稿記事 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 などとして利用できます。
返信する

“MV:質問”に戻る