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

问题描述 投票:0回答:1

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

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();

  },
javascript rotation drag phaser-framework
1个回答
0
投票

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

this.car.body.rotation = ...   // For radians
this.car.body.angle = ...   // For degrees
© www.soinside.com 2019 - 2024. All rights reserved.