6x6 색 사각형의 격자가 포함 된 EnchantJS로 HTML5/JavaScript 게임을 만들려고합니다. 나는 1 개의 이미지를 보여 주었지만 모든 이미지를 표시하기 위해 36x4 라인의 코드를 가지고 있기보다는 모든 것을 함수로 옮기고 싶었습니다. 코드는 라인 62 this.addChild(block);
에서 중단됩니다. 왜 이것이 작동하지 않는지 알 수가 없습니다. 나는 과거의 일을 기능들과 기능 들간의 정보 호출 방법에 대해 읽는 데 보냈다. 내가 뭘 잘못하고 있는지 알아낼 수 없으며 검색에서 답변을 찾을 수 없습니다. 나는 순전히 자바와 C++ 배경에서 왔기 때문에 문법을 엉망으로 만들고 뭔가를 이해하지 못한다고 생각합니다.Javascript OOP, functions
enchant();
window.onload = function() {
/*
* Game width and height.
* Note: Game scale is half so actual width=width/2 and
* actual heigh it height/2.
*/
var game = new Game(1280,768);
/*
* Game Preload Vars
*/
game.preload('res/bg2x.png',
'res/block.png');
game.fps = 30;
game.scale = 0.5;
game.onload = function() {
console.log("Game Loaded");
var scene = new SceneGame;
game.pushScene(scene);
}
game.start();
window.scrollTo(0, 0);
var SceneGame = Class.create(Scene, {
initialize: function() {
var game, bg;
Scene.apply(this);
game = Game.instance;
// Background
bg = new Sprite(1280,768);
bg.image = game.assets['res/bg2x.png'];
// Populate Screen
this.addChild(bg);
gridBuilder(500,75);
}
});
var gridBuilder = function(x,y) {
this.x=x;
this.y=y;
block = new Block;
block.x = x;
block.y = y;
this.block = block;
this.addChild(block); // THIS IS WHERE THE ERROR IS OCCURING.
};
var Block = Class.create(Sprite, {
// The player character.
initialize: function() {
// 1 - Call superclass constructor
Sprite.apply(this,[100, 100]);
this.image = Game.instance.assets['res/block.png'];
// 2 - Animate
this.animationDuration = 0;
this.addEventListener(Event.ENTER_FRAME, this.updateAnimation);
},
updateAnimation: function (evt) {
this.animationDuration += evt.elapsed * 0.001;
if (this.animationDuration >= 0.25) {
this.frame = (this.frame + 1) % 4;
this.animationDuration -= 0.25;
}
},
});
}
"휴식"방법? 오류가 있습니까? – deceze