我正在寻找一种在拖动方向上旋转精灵的方法

时间:2018-01-21 11:23:44

标签: javascript rotation drag phaser-framework

如何在拖动时沿拖动方向旋转精灵?我不希望精灵旋转到输入指针(toch,鼠标),如果它没有像素完美点击。此外,我仍然希望能够使用相位器框架在精灵上使用物理。

update: function() {
    this.game.physics.arcade.collide(this.car, this.block);
   // this.game.physics.arcade.overlap(this.car, this.traffic, this.bremsen);
/*if(this.car.input.pixelPerfectOver=true){

  this.angleBetweenPoints();
};*/
//this.car.rotate=this.car.angle;
//game.debug.spriteInputInfo(this.car, 32, 32);
  },

  angleBetweenPoints: function (point1, point2) {
this._dragPoint = new Phaser.Point(this.car.x, this.car.y);

Phaser.Math.angleBetween(this.car.x, 
                  this.car.y, game.input.activePointer.x,game.input.activePointer.y);

this.car.angle= Phaser.Math.angleBetween(this.game.input.activePointer.x, 
                  this.game.input.activePointer.y, this._dragPoint.x,this._dragPoint.y);

},


   animatecar: function(sprite, event) {



if ((this.angleBetweenPoints(this.car.y, this.game.input.activePointer.y)) > 0.1) {

    console.log(this.angleBetweenPoints(this.car.y, game.input.y));
  }
      this.car.input.enableDrag();

  },

1 个答案:

答案 0 :(得分:0)

您正在直接为精灵分配旋转,但在使用物理实体时,您应该更改身体上的旋转:

this.car.body.rotation = ...   // For radians
this.car.body.angle = ...   // For degrees