我目前正在尝试学习如何使用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
答案 0 :(得分:1)
事件名称区分大小写。您错误拼写了 EnterFrame 事件。
this.bind('EnterFrame', function() {
this.x = this.x+2;
});