❌
Global state soup: Storing game state on
or module globals
Why bad: scene transitions become fragile; debugging becomes chaotic
Better: scene data, registries, or a dedicated state manager
❌
Loading in : Loading assets in
instead of
Why bad: assets may not be ready when referenced
Better: load in
; use a Boot scene for all assets
❌
Frame-dependent logic: Using frame count instead of
Why bad: game speed varies with frame rate
Better: scale by
for consistent movement/timers
❌ Physics overkill: Using Matter for simple platformer collisions
Why bad: unnecessary complexity + perf cost
Better: Arcade covers most 2D collision needs
❌ Monolithic scenes: One giant scene with all game logic
Why bad: hard to extend; UI/menus/pause become hacks
Better: separate gameplay vs UI overlay vs menus
❌ Magic numbers everywhere: Hardcoded tuning values scattered in code
Why bad: balancing becomes painful; changes cause regressions
Better: config objects/constants and centralized tuning
❌
No pooling for spammy objects: Creating/destroying bullets/particles constantly
Why bad: GC spikes → stutters
Better: object pooling with groups +
/
❌ Assuming spritesheet frame dimensions: Using guessed frame sizes without verifying source asset
Why bad: wrong dimensions cause silent frame corruption; off-by-pixels compounds into broken visuals
Better: open asset file, measure frames, calculate with spacing/margin, verify math adds up
❌
Ignoring spritesheet spacing: Not specifying
for gapped spritesheets
Why bad: frames shift progressively; later frames read wrong pixel regions
Better: check source asset for gaps between frames; use
in loader config
❌ Hardcoding nine-slice colors: Using single background color for all UI panel variants
Why bad: transparent frame edges reveal wrong color for different asset color schemes
Better: per-asset background color config; sample from center frame (frame 4)
❌ Nine-slice with padded frames: Treating the full frame as the slice region when the art is centered/padded inside each tile
Why bad: edge tiles contribute interior fill, showing up as opaque “side bars” inside the panel
Better: trim tiles to their effective content bounds (alpha bbox) and composite/cache a texture; add ~1px overlap + disable smoothing to avoid seams
❌ Scaling discontinuous UI art: Scaling a cropped banner/ribbon row that contains internal transparent gaps
Why bad: the transparent gutters scale too, making the UI look “broken” or segmented
Better: slice into left/center/right (or similar), stretch only the center, and stitch into a cached texture at the target size
❌
全局状态混乱:将游戏状态存储在
或模块全局变量中
弊端:场景切换变得脆弱;调试难度大幅提升
优化方案:使用场景数据、注册表或专用状态管理器
❌
在中加载资源:在
而非
中加载资源
弊端:资源可能在引用时未加载完成
优化方案:在
中加载;使用启动场景处理所有资源加载
❌
依赖帧数的逻辑:使用帧数计数而非
弊端:游戏速度会随帧率变化
优化方案:使用
进行缩放,确保运动/计时器的一致性
❌ 物理系统过度使用:为简单平台跳跃游戏使用Matter物理
弊端:增加不必要的复杂度与性能开销
优化方案:Arcade物理足以满足大多数2D碰撞需求
❌ 单体式场景:将所有游戏逻辑放在一个庞大的场景中
弊端:难以扩展;UI/菜单/暂停功能会变成临时补丁
优化方案:将游戏玩法、UI浮层、菜单分离为不同场景
❌ 到处使用魔法数字:在代码中分散使用硬编码的调优数值
弊端:平衡调整变得繁琐;修改容易引发回归问题
优化方案:使用配置对象/常量,集中管理调优数值
❌
未对高频对象做对象池:频繁创建/销毁子弹/粒子等对象
弊端:垃圾回收峰值导致游戏卡顿
优化方案:使用对象组实现对象池,通过
/
复用对象
❌ 假设精灵表帧尺寸:未验证源资源就猜测帧尺寸
弊端:错误的尺寸会导致帧无声损坏;像素偏差会累积成视觉故障
优化方案:打开资源文件,测量帧尺寸,结合间距/边距计算,验证计算结果
❌
忽略精灵表间距:对带间隙的精灵表未指定
参数
弊端:帧会逐渐偏移;后续帧会读取错误的像素区域
优化方案:检查源资源的帧间隙;在加载器配置中设置
❌ 硬编码九宫格颜色:为所有UI面板变体使用单一背景色
弊端:透明帧边缘会因不同资源配色方案显示错误颜色
优化方案:为每个资源配置单独的背景色;从中心帧(第4帧)采样颜色
❌ 带内边距帧的九宫格:当艺术内容在每个 tile 中居中/带内边距时,将整个帧视为切片区域
弊端:边缘tile会填充内部区域,在面板内显示不透明的“侧边栏”
优化方案:将tile裁剪至有效内容边界(alpha包围盒),合成并缓存纹理;添加约1px重叠并禁用平滑以避免接缝
❌ 缩放不连续的UI素材:缩放包含内部透明间隙的裁剪横幅/带状素材
弊端:透明间隙也会被缩放,导致UI看起来“破损”或分段
优化方案:将素材切割为左/中/右(或类似结构),仅拉伸中间部分,然后拼接成目标尺寸的缓存纹理