座標ズレ修正
by
cutfloss
04/29 [2026/04/29 22:21:36]
PC、タブレットのタップずれ補正し、ブーストボタンを押せるようになる
-
/*
* @title 座標ズレ修正
* @description PC、タブレットのタップずれ補正し、ブーストボタンを押せるようになる
* @private
*/
javascript:(function(){
const cvs = document.querySelector('canvas');
if(!cvs) return;
/* 座標変換:余白を消し、解像度倍率を合わせる */
const getFixPos = (e) => {
const r = cvs.getBoundingClientRect();
const cx = e.clientX || (e.touches ? e.touches[0].clientX : 0);
const cy = e.clientY || (e.touches ? e.touches[0].clientY : 0);
return {
x: (cx - r.left) * (cvs.width / r.width),
y: (cy - r.top) * (cvs.height / r.height),
rawX: cx,
rawY: cy
};
};
/* イベント発火時にゲームの内部関数を「正しい座標」で叩く */
const inject = (e) => {
const p = getFixPos(e);
/* 1. ブースト判定へ直接送る */
if(typeof isInBoostButtonArea === 'function' && isInBoostButtonArea(p.x, p.y)) {
if(e.type === 'mousedown' || e.type === 'touchstart') triggerBoost();
return;
}
/* 2. 移動入力の基準点(touchStartPos)を強制補正 */
if(e.type === 'mousedown' || e.type === 'touchstart') {
window.touchStartPos = { x: p.rawX, y: p.rawY };
window.inputState.drawing = true;
}
};
/* 既存の処理より先に割り込む(true設定) */
window.addEventListener('mousedown', inject, true);
window.addEventListener('touchstart', inject, {passive: false, capture: true});
console.log('座標補正パッチ:稼働中(軽量モード)');
})();
-
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。