在JavaScript中使用box2D时无法移动

时间:2013-09-25 09:12:11

标签: javascript box2d box2dweb

我使用Crafty引擎,我使用Twoway按键移动我的播放器,但是当我使用box2D时,我的播放器无法移动,有人可以帮助我吗?

Crafty.c('Player', {
    currentAnim: null,
    init: function() {
        this.requires('2D, Canvas, spr_zoro_stand, SpriteAnimation, Keyboard, Twoway, DOM, Box2D')
            .attr({x: 100, y: 200})
            .box2d({
                bodyType: 'dynamic',
                density : 10,
                friction : 1
            })
        .animate("Stand",0, 0, 3).twoway(2,1);
        this.currentAnim = this.animate("Stand", 12, -1);

        this.bind('NewDirection', function(data) {
            if (data.x > 0) {
                this.currentAnim.stop();
                this.removeComponent("spr_zoro_stand");
                this.addComponent("spr_zoro_run");
                this.animate('runRight', 0, 0, 7);
                this.unflip("X");
                this.currentAnim = this.animate('runRight', 24, -1);
            } else if (data.x < 0) {
                this.currentAnim.stop();
                this.removeComponent("spr_zoro_stand");
                this.addComponent("spr_zoro_run");
                this.animate('runRight', 0, 0, 7);
                this.flip("X");
                this.currentAnim = this.animate('runRight', 24, -1);
            }else {
                this.currentAnim.stop();
                this.removeComponent("spr_zoro_run");
                this.addComponent("spr_zoro_stand");
                this.currentAnim = this.animate('Stand', 12, -1);
            }
        });
    }
});

0 个答案:

没有答案