Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have coded my main menu for the game in html/css and need the image buttons to function with the engine using JavaScript.
For example:

Skip (Enable) Which skips the menu when you come back to play to continued the game.

(Disable ) Which will return it normal where you can see menu again

Skip – one image button red off and when click turns green on

Restart - Which when clicked opens a box with two images in it and text. (image + Yes, image + NO) if you click YES it restarts game and when you click NO resumes game.

Sound - will have one image button which will be red (Default ON) and when click turns green sound turns Off.

Example: function ENGINE_get_option_state(opt:string):string { return…; }

ENGINE_trigger_sound(…)

share|improve this question

1 Answer 1

You bind the images/buttons to a variable, then you can access that from your javascript.

For example:

<img id="startGame" src="image.png" />

Here's how you access the image from javascript:

var startGame = document.getElementById('startGame');

Now that you have the element in a variable you can do what you want with it. Just setup a function that executes the code you want the button to do. The function can look something like this:

startGame.onclick = function() {
alert('Game started!'); // Execute code here.
}

Very basic, hope this helps.

EDIT: Paste the following to a html document, and you have something to experiment with.

<!DOCTYPE HTML>
<html>
<head>
<style>
#startGame {width:100px; height:50px; background:black;}
</style>
</head>
<body>
<div id="startGame"></div>
<script>
window.onload = function() {
    var startGame = document.getElementById('startGame');

    startGame.onclick = function() {
        alert('Game started!');
    }
}
</script>
</body>
</html>
share|improve this answer
    
Thanks for the reply and also this html/css menu is for an app game for both Android and ISO (iphone, ipad, and itouch). When you click play it plays the game on the phone its installed on. –  akamerc Jul 14 '12 at 7:52
    
Shouldn't matter since javascript is a browser technology not a phone specific language. Even though browsers render things differently this code is so basic it should work in all of them. –  hustlerinc Jul 14 '12 at 8:37
    
Well first of all I'm not getting paid by this company and yes its a project and the reason I'm asking for help is because I'm knew at this and want to learn –  akamerc Jul 15 '12 at 11:21
    
Do you know a website where I can read on this to learn the coding. Also, sorry for any misunderstanding here. –  akamerc Jul 15 '12 at 11:22
    
teamtreehouse.com and codecademy.com are both free websites offering good online courses. Try them out and go with the one you like the best. –  hustlerinc Jul 15 '12 at 11:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.