我无法获取我的JavaScript / Enchant.js代码来解决我做错的事情 [英] I can't get my JavaScript/ Enchant.js code to work what am I doing wrong
本文介绍了我无法获取我的JavaScript / Enchant.js代码来解决我做错的事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Enchant.js的新手和js的新手,想知道我的代码出了什么问题
所以我的代码没有显示任何我跟踪的示例代码enchant.js网站。有人可以告诉我我做错了什么。
这是我遵循的示例代码
New to Enchant.js and new to js, and want to know what is wrong with my code
So my code displays nothing I followed a sample code on the enchant.js website. Could someone please tell me what I'm doing wrong.
Here is the sample code i followed
// This sample shows an image that will move to the right when clicked
enchant();
window.onload = function () {
var game = new Game(320, 320);
game.preload('chara0.gif');
game.onload = function() {
var scene = new Scene();
var sprite = new Sprite(32, 32);
sprite.image = game.assets['chara0.gif'];
scene.addChild(sprite);
sprite.addEventListener('touchstart', function() {
sprite.x += 1;
});
game.pushScene(scene);
};
game.start();
};
这是我的代码
//index.html
and here is my code
//index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Game.js</title>
<script src="js/enchant.js"></script>
<script src="js/main.js"></script>
</head>
<body>
</body>
</html>
//main.js
//main.js
enchant();
window.onload = function(){
//Setting up the game
var game = new Core(500, 700);
//preloading the res
game.preload('res/ghost.png');
// setting the fps view and onload
game.fps = 20;
game.scale = 0;
game.onload = function(){
//setting up the scene
var mainFrame = new Scene();
mainFrame.backgroundColor = 'blue';
//loading image from preload into mainframe
var playerOne = new Sprite(32, 32);
playerOne.image = game.assets['res/ghost.png'];
//finallying wellcome to the game ghost.
mainFrame.addChild(playerOne);
//moving ghost aka playerOne around.
playerOne.addEventListener('touchstart', function(){
if(LEFT_BUTTON_DOWN){
playerOne.x +=0.1;
}
});
//game.pushScene(mainFrame);
game.rootScene.addChild(mainFrame);
}
game.start();
};
推荐答案
这篇关于我无法获取我的JavaScript / Enchant.js代码来解决我做错的事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文