Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (808)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (872)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [libgdx] How can rotate multiple texture same like one texture?  (Read 1302 times)
0 Members and 1 Guest are viewing this topic.
Offline sinich13

Innocent Bystander





« Posted 2017-05-05 02:35:05 »



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.
Offline sarcastibots

Junior Devvie


Medals: 2
Projects: 2



« Reply #1 - Posted 2017-05-05 03:41:22 »

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
1  
2  
3  
4  
5  
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
1  
2  
3  
4  
5  
6  
7  
8  
9  
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.

Offline dfour
« Reply #2 - Posted 2017-05-05 08:29:56 »

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.

1  
2  
3  
4  
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.
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (848 views)
2019-09-04 15:33:17

hadezbladez (5799 views)
2018-11-16 13:46:03

hadezbladez (2605 views)
2018-11-16 13:41:33

hadezbladez (6215 views)
2018-11-16 13:35:35

hadezbladez (1501 views)
2018-11-16 13:32:03

EgonOlsen (4736 views)
2018-06-10 19:43:48

EgonOlsen (5794 views)
2018-06-10 19:43:44

EgonOlsen (3278 views)
2018-06-10 19:43:20

DesertCoockie (4176 views)
2018-05-13 18:23:11

nelsongames (5503 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!