This is a noob question but I have not worked to much with JavaScript as of yet. I have a game I am programming for class and so far everything looks okay but I cannot get my main.js file to recognize the me for melonJS which is what I am using as part of the game engine. The code is below:
main.js source code:
main.js:
// JavaScript Document
var jsApp = {
onload: function(){
"use strict";
if (!me.video.init('jsapp', 320, 240, true)){
alert ("html 5 canvas is not supported by this browser.");
return;
}
me.loader.onload = this.loaded.bind(this);
me.loader.preload(resources);
me.state.change(me.state.LOADING);
},
loaded: function(){
me.state.set(me.state.PLAY, new Playscreen());
me.entityPool.add("player", PlayerEntity);
me.state.change(me.state.PLAY);
}
};
window.onReady(function(){
"use strict";
jsAPP.onload();
});
here is the my index code file:
<!DOCTYPE html>
<html>
<head>
<title>Adventure Game</title>
</head>
<body>
<div id="wrapper" style="width:640px; text-align:center; margin-
left:auto; margin-right:auto;">
<div id="jsapp">
<script type="text/javascript" src="melonJS.js"></script>
<script type="text/javascript" src="resources.js"></script>
<script type="text/javascript" src="screen.js"></script>
<script type="text/javascript" src="entity.js"></script>
<script type="text/javascript" src="main.js"></script>
</div>
</div>
</body>
</html>
JavaScript variables are case-sensitive; At the start of main.js, you declare a variable called
jsApp
. At the end of the same file, you referencejsAPP
, which is not the same. Change the last one tojsApp
, and it will advance a bit further.See the MDC Glossary for more information: