我目前正在尝试学习如何使用crafty.js 来创建游戏。现在方形精灵被绘制了,但我无法让它做任何事情。这是我的游戏的代码:
Game = {
// Initialize our game
start: function() {
// Start crafty and set a background color
Crafty.init(640, 480);
Crafty.background('green');
Crafty.sprite(16, "assets/square.png", {square:[0,0]});
Crafty.c('SquareControls', {
init: function() {
this.bind('enterframe', function() {
this.x = this.x+2;
});
return this;
}
});
//// SCENES ////
Crafty.scene("main", function() {
var square = Crafty.e("2D, Canvas, square, SquareControls")
.attr({x:32, y:32, width:16, height:16});
});
Crafty.scene("main");
} // end start()
} // end Game class