LibGDX - Rotate a 2d array of sprites around their center

后端 未结 1 544
暗喜
暗喜 2021-01-29 02:09

I have a square 2d array of sprites and im trying to rotate all of them around the center position of the map, but after many attempts the sprites seem to be only rotating aroun

相关标签:
1条回答
  • 2021-01-29 02:55

    the first thing that comes to mind is, if I understand your question, you tell all sprites where is the point which must rotate using: sprite.setOrigin(yourPointVector2.x, yourPointVector2.y); sprite.rotation(yourRotation);

    Edit new edited for your comment

    simple test for 1 sprite rotation, maybe is not the best way but it occurred to me that right now. enter image description here Like this helps you, if your sprite is at 50.50, of the your map, and the center of your map is 400, 240, I would create a variable that will store the initial position of the sprite,

    example:

    //is stored only once, because if not will store where you are during rotation
    
    yourVectorPosInicial.x = sprite.getX();
    yourVectorPosInicial.v = sprite.getY();
    
    yourVectorCenterMap.x = 400f;
    yourVectorCenterMap.y = 240f;` 
    
    youtSprite.setOrigin(yourVectorCenterMap.x-yourVectorPosInicial.x , 
                         yourVectorCenterMap.y-yourVectorPosInicial.y);
    
    //this in your Draw or update render
    
    sprite.rotation(10f);
    
    0 讨论(0)
提交回复
热议问题