1

私は 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);
            }
        });
    }
});
4

0 に答える 0