简体   繁体   English

精灵旋转与碰撞 PIXIJS

[英]Sprite rotation with collision PIXIJS

I have a problem with my pixiJS App.我的 pixiJS 应用程序有问题。 I have many sprites that I can move in my scene.我有很多可以在场景中移动的精灵。 My goal is to create a plan with collisions between sprites, for that I use the bump plugin and the rectangleCollision function: https://github.com/kittykatattack/bump/我的目标是创建一个精灵之间碰撞的计划,为此我使用凹凸插件和矩形碰撞 function: https://github.com/kittykatattack/bump/

let collision = b.rectangleCollision(selectCont,c2,true,false,true);

It works (the middle case on the pic) if my sprites have no rotation but if I rotate the sprites the collisions don't work (left and right case in the pic).如果我的精灵没有旋转,它可以工作(图片中的中间情况),但如果我旋转精灵,碰撞不起作用(图片中的左右情况)。

截屏

I think it's a problem with sprite bounds but I have no idea.我认为这是精灵边界的问题,但我不知道。

I have an array with all my sprites and I have a function when I right click on a sprite it applies a rotation and when I want to apply my rotation it does work but my collision is not correct我有一个包含所有精灵的数组,当我右键单击精灵时,我有一个 function

for (var j = 0; j < cont.length; j++) {
  var c2 = cont[j];
  b.contain(c2, {x: 0, y: 0, width: 2400, height: 1800}, true);
  
  if(selectCont!=c2){
    if(activeCollision == true){
       let collision = b.hit(selectCont,c2,endCollision,false,true);
    }
  }
}

// function to apply a rotation to sprite
function rotate(){
  this.rotation -= Math.PI/4;
}

The rotation property of sprites defaults to rotating the sprite around the top left vertice, not the center. sprite 的rotation属性默认为围绕左上角的顶点旋转 sprite,而不是中心。 The pivot point can be changed with the sprites pivot property, as shown here: pivot 点可以通过精灵pivot属性进行更改,如下所示:

sprite.pivot.set(sprite.width/2,sprite.height/2);

This will set the sprites pivot point to be right in the center of itself.这会将精灵 pivot 点设置在其自身的中心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM