Hi,
I want to rotate multiple texture same like this picture on libgdx.
How can do this? Or can multiple images create one sprite?
Thanks.
Hi,
I want to rotate multiple texture same like this picture on libgdx.
How can do this? Or can multiple images create one sprite?
Thanks.
I can think of two ways to do this.
You could build a larger texture from your 4 smaller textures at run time using pixmaps and then rotate the large texture.
pseudo code
Pixmap bigPixmap = new Pixmap(SIZE_BIG_PIXMAP)
bigPixmap.drawPixmap(texture1, tex1Location)
bigPixmap.drawPixmap(texture2, tex2Location)
Drawable bigDrawable = drawableFromPixMap(bigPixmap)
you could create a class that has 4 sprite or actor fields with a rotate method that calculates the new positions using fancy vector math.
pseudo code
Sprite tex1
Sprite tex2
...
rotate(Vector2 origin, float angle) {
Vector2 tex1Position = fancyVectorMath1(origin, angle)
tex1.setTransform(tex1Position, angle)
...
}
Either way you’ll probably want to use a Sprite or Image to wrap the texture rather than manipulating the Texture class directly.
If all the images are sprites you could use the setOrigin method to set their origin at the same world position. The images will then all scale and rotate from the same point.
tex1.setOrigin(0, -100)
tex2.setOrigin(0, -200)
tex3.setOrigin(0, -300)
tex4.setOrigin(0, -400)
Then once you finish rotating you can use setOriginCenter to place the origin back the the middle so they can be rotated independently again.