我试图使用Hexi(JS游戏引擎)重建超级马里奥兄弟级别1-1。
我的问题在于javascript本身。
我声明了几个要在游戏中使用的全局变量
var marioStats = {
'startingPos':[g.canvas.width / 8, 185],
'lives': 3,
'currentPos':[g.canvas.width / 8, 185],
'checkPointPos':[g.canvas.width / 8, 185],
};
var spritesResources = ['resources/graphics/item_objects.png',
'resources/graphics/smb_enemies_sheet.png',
'resources/graphics/tile_set.png',
];
var spritesFrames = { 'simpleBlock': [g.frame(spritesResources[2], 15,1, 17,13)],
'coinBlock': [g.frame(spritesResources[0], 1,80, 14,14)],
'usedBlock': [g.frame(spritesResources[2], 48,1, 14,14)],
'gumba': [g.frame(spritesResources[1], 0,4, 15,15)],
'koopa': [g.frame(spritesResources[1], 90,1, 14,22)],
};
var levelLayout = {
'META': {
'checkPoints': [],
'renderArea': 0,
'horizontalPos': 0,
},
0: [ ['simpleBlock', spritesFrames['simpleBlock'][0], [g.canvas.width /2, g.canvas.height /4]]
],
1: [
],
2: [
],
};
现在河西的工作方式如下:
var g = hexi(255, 223, levelSetup, thingsToLoad, load);
g.start();
加载" thingsToLoad"对象数组 河西将运行" levelSetup"
我可以在levelSetup中访问marioStats和sepriteResources 但是当我尝试访问spritesFrames或levelLayout时,它给了我 undefined
function levelSetup() {
decors.visible = false;
var level11 = g.group();
var gameMusic = g.sound('resources/music/main_theme.ogg');
gameMusic.play();
var lvlbg = g.sprite("resources/graphics/level_1.png");
level11.addChild(lvlbg);
var lvlBlocks = [], lvlEnemies = []; // hold the blocks and enemies of the level to perform collesion on them
renderLvlSprite(levelLayout[0], lvlBlocks, level11); // this line doesn't work since levelLayout is undefined
g.state = levelPlay;
}
我在这里做错了什么?
spriteResources下面的所有变量都是未定义的!