将事件绑定到狡猾.js中的实体
Binding events to entities in crafty.js
我目前正在尝试学习如何使用狡猾.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
事件名称区分大小写。您拼错了 EnterFrame 事件。
this.bind('EnterFrame', function() {
this.x = this.x+2;
});
相关文章:
- fullpage.js和物化.js;使用实体侧导航禁用鼠标滚动
- Famo.us Js-将实体(粒子)设置到位置的动画
- Breeze.js getEntities不返回任何实体
- Sails Js请求实体过大错误
- 节点js请求实体太大,需要多次上传
- 将jsondecoded字符串中的js-eescaped-char(或hex-char?)转换为php中的html实体
- 如何在 Sequelize Js 中使用 Promise 来返回实体
- 创建Crafty JS实体的类(类的类?)
- 将事件绑定到狡猾.js中的实体
- Breeze JS:有没有办法从data.results中查询实体
- Knockout.js toJSON 从 Breeze 实体创建空对象
- Node.js/JavaScript-避免用户输入脚本和html实体
- Breeze.js实体框架多个一对一的相同类型(Parent->Child-childOne,Child-chil
- l20n.js-如何从javascript访问本地化子实体
- 在没有实体框架的情况下使用Breeze.js
- 解码Angular JS中的HTML实体
- jQuery(或JS)解码字符串中的HTML字符实体
- 在phaser.js实体中显示Math
- 移动Phoria.js中的实体
- Immutable.js:通过索引(而不是键)获取map实体