admin管理员组文章数量:1279174
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?
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?
Share Improve this question edited Dec 23, 2011 at 18:56 Dropped43 asked Dec 23, 2011 at 18:49 Dropped43Dropped43 3452 gold badges4 silver badges11 bronze badges 5- I don't know if you need to get that plex. It sounds like you just want to show an intro screen, maybe with a title and some instructions. Please see my updated answer below with code sample. Good luck! – Matt Cashatt Commented Dec 23, 2011 at 18:59
- Yes, just a intro screen and stuff. I looked at your updated answer and it seems really simple! Thanks, I'll play around with it. – Dropped43 Commented Dec 23, 2011 at 19:03
- Great! Please select my answer as correct (green check mark) if you use it. I could really use the points! – Matt Cashatt Commented Dec 23, 2011 at 19:04
- Also, you DO understand that you need to reference the jQuery framework for my solution to work, right? Instructions for that can be found here: jquery. – Matt Cashatt Commented Dec 23, 2011 at 19:05
- Yes I do understand that, I have worked with jQuery many times before, thanks! – Dropped43 Commented Dec 23, 2011 at 19:08
3 Answers
Reset to default 3Populate 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:
<div id="SplashScreen">
<h1>Game Title</h1>
<input id="StartButton" type="button" value="Start"/>
</div>
<canvas id="GameCanvas" style="display: none;">Game Stuff</canvas>
<script>
$("#StartButton").click(function () {
$("#SplashScreen").hide();
$("#GameCanvas").show();
});
</script>
Simple, use a regular HTML img
that is located 'above' your canvas until everything is loaded / initialised.
function startGame() {
alert('Are you sure you want to make a new Game?');
}
function continueGame() {
alert('Continue Game?');
}
body, button {
color: blue;
text-align: center;
font-family: cursive;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Game Title</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Game Title</h1>
<script src="script.js">startGame()</script>
<button onclick="startGame()">New Game</button>
<button onclick="continueGame()">Continue Game</button>
</body>
</html>
本文标签: javascriptCreating a start screen for a HTML5 Canvas GameStack Overflow
版权声明:本文标题:javascript - Creating a start screen for a HTML5 Canvas Game? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741267187a2368698.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论