fix(game): 修复格子正方形和图片尺寸问题,用setDisplaySize精确控制角色图片占一格
This commit is contained in:
@@ -14,9 +14,9 @@ export class BossVP extends EnemyBase {
|
|||||||
) {
|
) {
|
||||||
super(scene, pathPoints, 800, 40, 30, 150, 'enemy-boss')
|
super(scene, pathPoints, 800, 40, 30, 150, 'enemy-boss')
|
||||||
this.onDestroyTower = onDestroyTower
|
this.onDestroyTower = onDestroyTower
|
||||||
// 放大 BOSS
|
// BOSS 放大到 1.3 个格子(跨格的威压感)
|
||||||
const bossScale = Math.min(this.cellW, this.cellH) / 128 * 1.3
|
const bossSize = this.cellW * 1.3
|
||||||
this.imageSprite.setScale(bossScale)
|
this.imageSprite.setDisplaySize(bossSize, bossSize)
|
||||||
this.imageSprite.setDepth(12)
|
this.imageSprite.setDepth(12)
|
||||||
// BOSS 出现特效
|
// BOSS 出现特效
|
||||||
scene.cameras.main.flash(800, 255, 0, 0, false)
|
scene.cameras.main.flash(800, 255, 0, 0, false)
|
||||||
|
|||||||
@@ -87,10 +87,10 @@ export abstract class EnemyBase {
|
|||||||
this.y = pathPoints[0].y
|
this.y = pathPoints[0].y
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用 AI 图片精灵,尺寸按格子缩放
|
// 用 AI 图片精灵,精确设为格子尺寸的 75%(怪物比塔小一点)
|
||||||
|
const enemySize = cellW * 0.75
|
||||||
this.imageSprite = scene.add.image(this.x, this.y, spriteKey)
|
this.imageSprite = scene.add.image(this.x, this.y, spriteKey)
|
||||||
const scale = Math.min(cellW, cellH) / 128 * 0.75
|
this.imageSprite.setDisplaySize(enemySize, enemySize)
|
||||||
this.imageSprite.setScale(scale)
|
|
||||||
this.imageSprite.setDepth(10)
|
this.imageSprite.setDepth(10)
|
||||||
|
|
||||||
this.healthBar = scene.add.graphics()
|
this.healthBar = scene.add.graphics()
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ export class OldEmployee extends EnemyBase {
|
|||||||
constructor(scene: Phaser.Scene, pathPoints: PathPoint[]) {
|
constructor(scene: Phaser.Scene, pathPoints: PathPoint[]) {
|
||||||
super(scene, pathPoints, 150, 50, 8, 30, 'enemy-old')
|
super(scene, pathPoints, 150, 50, 8, 30, 'enemy-old')
|
||||||
this.shieldCount = 3
|
this.shieldCount = 3
|
||||||
// 老员工图片稍大
|
// 老员工比普通怪略大(0.85 个格子)
|
||||||
const scale = Math.min(this.cellW, this.cellH) / 128 * 0.9
|
this.imageSprite.setDisplaySize(this.cellW * 0.85, this.cellW * 0.85)
|
||||||
this.imageSprite.setScale(scale)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getQuote(): string { return getRandomQuote('OldEmployee') }
|
getQuote(): string { return getRandomQuote('OldEmployee') }
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
MAP_COLS,
|
MAP_COLS,
|
||||||
MAP_ROWS,
|
MAP_ROWS,
|
||||||
GAME_WIDTH,
|
GAME_WIDTH,
|
||||||
|
GAME_HEIGHT,
|
||||||
HUD_HEIGHT,
|
HUD_HEIGHT,
|
||||||
PATH_WAYPOINTS,
|
PATH_WAYPOINTS,
|
||||||
COLOR_PATH,
|
COLOR_PATH,
|
||||||
@@ -36,11 +37,12 @@ export function buildPathTiles(
|
|||||||
|
|
||||||
export const PATH_TILES = buildPathTiles(PATH_WAYPOINTS)
|
export const PATH_TILES = buildPathTiles(PATH_WAYPOINTS)
|
||||||
|
|
||||||
/** 计算格子尺寸 */
|
/** 计算格子尺寸(正方形格子,取宽高中较小值保证正方形) */
|
||||||
export function getCellSize() {
|
export function getCellSize() {
|
||||||
const cellW = Math.floor(GAME_WIDTH / MAP_COLS)
|
const rawW = Math.floor(GAME_WIDTH / MAP_COLS) // 80
|
||||||
const cellH = Math.floor((720 - HUD_HEIGHT) / MAP_ROWS)
|
const rawH = Math.floor((GAME_HEIGHT - HUD_HEIGHT) / MAP_ROWS) // 55
|
||||||
return { cellW, cellH }
|
const cell = Math.min(rawW, rawH) // 55 → 正方形
|
||||||
|
return { cellW: cell, cellH: cell }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -56,10 +56,10 @@ export abstract class TowerBase {
|
|||||||
this.px = gridX * cellW + cellW / 2
|
this.px = gridX * cellW + cellW / 2
|
||||||
this.py = HUD_HEIGHT + gridY * cellH + cellH / 2
|
this.py = HUD_HEIGHT + gridY * cellH + cellH / 2
|
||||||
|
|
||||||
// 用 AI 图片作为精灵
|
// 用 AI 图片作为精灵,精确设为格子尺寸的 85%(留边距)
|
||||||
|
const imgSize = cellW * 0.85
|
||||||
this.imageSprite = scene.add.image(this.px, this.py, spriteKey)
|
this.imageSprite = scene.add.image(this.px, this.py, spriteKey)
|
||||||
const scale = Math.min(cellW, cellH) / 128 * 0.85
|
this.imageSprite.setDisplaySize(imgSize, imgSize)
|
||||||
this.imageSprite.setScale(scale)
|
|
||||||
this.imageSprite.setDepth(10)
|
this.imageSprite.setDepth(10)
|
||||||
|
|
||||||
this.staminaBar = scene.add.graphics()
|
this.staminaBar = scene.add.graphics()
|
||||||
|
|||||||
Reference in New Issue
Block a user