You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Canvas内收集物不显示:弃用Phaser后硬币随机生成失效求助

Troubleshooting Disappearing Randomly Spawned Coins in Your Custom Game

Hey there! Sorry to hear your coins vanished after a tiny tweak—let’s break down the most likely issues here, since you’ve already got sprite movement and collision detection locked in.

  • Double-check your randomRange parameter bounds
    This is the first place to look. If you adjusted the min/max values for your X or Y coordinates even slightly, you might be spawning coins entirely outside the canvas. For example:

    • If you changed randomRange(0, canvas.width) to randomRange(canvas.width, 2000) (way too far right)
    • Or forgot to subtract the coin’s width/height from the max bounds (e.g., using canvas.height instead of canvas.height - coinSprite.height, which could push the coin below the visible area)
      Make sure your spawn logic keeps coordinates within 0 ≤ x ≤ canvas.width - coinWidth and 0 ≤ y ≤ canvas.height - coinHeight to ensure the whole coin stays visible.
  • Verify sprite initialization changes
    Did you tweak anything about how the coin sprite is set up? Even small changes can break visibility:

    • Accidentally setting coinSprite.visible = false or a z-index lower than your background (so it’s covered up)
    • Changing the sprite’s anchor point (e.g., switching from (0,0) to (1,1) without adjusting spawn coordinates, which could shift the coin off-screen)
    • Messing up the sprite’s image source path (though this often throws an error, but not always—double-check the console for 404s)
  • Check for unintended position transformations
    If you added new code that modifies the coin’s position after spawning (like a camera follow system that offsets the view, or a parent container that’s shifted), that could yank the coin out of the visible area. Even a tiny change to a translate call in your draw function could be the culprit.

  • Debug with hardcoded coordinates
    To narrow things down, temporarily replace your random spawn logic with the exact coordinates that worked before (the top-left corner where you saw the coin initially). If it shows up again, you know the problem is definitely with your randomRange setup. If it still doesn’t appear, the issue lies in how the coin is being rendered or initialized post-tweak.

内容的提问来源于stack exchange,提问作者Thunderfist987

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:22:13