提交 a92b6765 authored 作者: lidongxu's avatar lidongxu

暂时适配了ipad_-但是大屏上球的飞行路径没了

上级 7dd0cad2
/** /**
* 大屏设计稿尺寸(与 minigame 竖版一致),所有渲染在此坐标系下绘制 * 大屏设计稿尺寸,所有渲染在此坐标系下绘制
* SCREEN_WIDTH 固定 375,SCREEN_HEIGHT 根据小游戏端屏幕比例动态调整
*/ */
export const SCREEN_WIDTH = 375 export const SCREEN_WIDTH = 375
export const SCREEN_HEIGHT = 667 export let SCREEN_HEIGHT = 667
export const SAFE_AREA_TOP = 0 export const SAFE_AREA_TOP = 0
export const SAFE_AREA_BOTTOM = 0 export const SAFE_AREA_BOTTOM = 0
/**
* 根据小游戏端的屏幕宽高比调整大屏设计稿高度
* 保持 SCREEN_WIDTH=375 不变,高度 = 375 / ratio
* @param {number} ratio 屏幕宽高比(width / height)
*/
export function configureScreenRatio(ratio) {
if (!ratio || ratio <= 0) return
const newHeight = Math.round(SCREEN_WIDTH / ratio)
if (newHeight === SCREEN_HEIGHT) return
SCREEN_HEIGHT = newHeight
}
...@@ -11,7 +11,7 @@ import { drawShooter } from './renderer/shooter.js' ...@@ -11,7 +11,7 @@ import { drawShooter } from './renderer/shooter.js'
import { drawGameInfo, drawTeamResultOverlay } from './renderer/gameinfo.js' import { drawGameInfo, drawTeamResultOverlay } from './renderer/gameinfo.js'
import { detectAndCreateBursts, updateAndDrawBursts, clearPrevGrid } from './renderer/explosion.js' import { detectAndCreateBursts, updateAndDrawBursts, clearPrevGrid } from './renderer/explosion.js'
import { drawIdleScreen } from './renderer/idleScreen.js' import { drawIdleScreen } from './renderer/idleScreen.js'
import { SCREEN_WIDTH, SCREEN_HEIGHT } from './constants.js' import { SCREEN_WIDTH, SCREEN_HEIGHT, configureScreenRatio } from './constants.js'
const container = document.getElementById('game-container') const container = document.getElementById('game-container')
const canvas = document.getElementById('game-canvas') const canvas = document.getElementById('game-canvas')
...@@ -188,6 +188,7 @@ function drawCountdownOverlay(totalWidth) { ...@@ -188,6 +188,7 @@ function drawCountdownOverlay(totalWidth) {
// ─── 主循环 ─────────────────────────────────────────────────────────────────── // ─── 主循环 ───────────────────────────────────────────────────────────────────
let _lastPlayerCount = 1 let _lastPlayerCount = 1
let _lastScreenHeight = SCREEN_HEIGHT
function loop() { function loop() {
frameCount++ frameCount++
...@@ -196,14 +197,20 @@ function loop() { ...@@ -196,14 +197,20 @@ function loop() {
const connStatus = getConnectionStatus() const connStatus = getConnectionStatus()
const playerCount = states.length || 1 const playerCount = states.length || 1
// 从任意一个玩家的 state 中提取屏幕比例,在渲染前统一配置
if (states.length > 0 && states[0].screenRatio) {
configureScreenRatio(states[0].screenRatio)
}
// 按队伍分组 // 按队伍分组
const teamAStates = states.filter(s => getPlayerTeam(s.playerId ?? 1) === 'A') const teamAStates = states.filter(s => getPlayerTeam(s.playerId ?? 1) === 'A')
const teamBStates = states.filter(s => getPlayerTeam(s.playerId ?? 1) === 'B') const teamBStates = states.filter(s => getPlayerTeam(s.playerId ?? 1) === 'B')
const totalSlots = Math.max(teamAStates.length + teamBStates.length, 1) const totalSlots = Math.max(teamAStates.length + teamBStates.length, 1)
// 人数变化时重新计算缩放 // 人数变化 或 屏幕高度变化时重新计算缩放
if (totalSlots !== _lastPlayerCount) { if (totalSlots !== _lastPlayerCount || SCREEN_HEIGHT !== _lastScreenHeight) {
_lastPlayerCount = totalSlots _lastPlayerCount = totalSlots
_lastScreenHeight = SCREEN_HEIGHT
applyScaler(totalSlots) applyScaler(totalSlots)
// 清理消失玩家的碎裂列表和grid快照 // 清理消失玩家的碎裂列表和grid快照
for (const pid of playerBursts.keys()) { for (const pid of playerBursts.keys()) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论