为 HTML5 Canvas 游戏创建开始屏幕?
我们大多数人都知道,Firefox、Safari 和 Chrome 的速度惊人的 Javascript 引擎对 HTML5 Canvas 元素提供了更好的支持。
最近,我一直在尝试使用 Javascript 和 Canvas 进行游戏开发,我想知道为 Javascript 游戏创建开始屏幕的好方法是什么。
到目前为止,我唯一的想法是在游戏之前创建一个 UI,并使用 Javascript 进行填充,并使用事件侦听器来跟踪鼠标以及鼠标单击按钮的时间。但我不确定这是否明智。
在 Javascript 游戏中设置起始屏幕等的好方法是什么?任何帮助都会有用,谢谢!
更新:感谢您的快速回复!很多人建议在游戏加载之前放置一个 img,等等。那么我是否需要编写一个资产管理器或某种东西 - 来检查所有图像等何时加载?
Most of us know that HTML5 Canvas element is having much better support with these amazingly fast Javascript Engines from Firefox, Safari and Chrome.
So recently I have been experimenting with game development with Javascript and the Canvas, and I am wondering what would be a good approach to be creating a Start Screen for a Javascript Game.
So far, the only idea I have would be creating a UI before the game and stuff with Javascript and use Event Listeners to track the mouse and when they click buttons. But I'm not sure if this a wise thing to do.
What would a good way to go about a Starting Screen, etc. in a Javascript game? Any help would be useful, thanks!
UPDATE: Thanks for the blazing fast reply(s)! A lot of you are suggesting placing a img until the game loads, etc. So do I need to write a asset manager or some sort - to check when all the images etc. are loaded?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用您的初始屏幕填充 div 标签。让它在页面加载时显示并隐藏画布。将“开始”按钮添加到 div 标签,并在其单击事件中,隐藏启动屏幕 div 标签并使用 jQuery 或经典 JavaScript 显示画布。
下面是一些使用 jQuery 的示例代码:
Populate a div tag with your splash screen. Have it showing on page load and have your canvas hidden. Add a 'start' button to the div tag and on it's click event, hide the splash screen div tag and show the canvas using either jQuery or classic JavaScript.
Here is some sample code using jQuery:
很简单,使用位于画布“上方”的常规 HTML
img
,直到所有内容都加载/初始化。Simple, use a regular HTML
img
that is located 'above' your canvas until everything is loaded / initialised.