Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (517)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (577)
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] Particles doesnt rotate  (Read 814 times)
0 Members and 1 Guest are viewing this topic.
Offline T1663R

Junior Duke


Medals: 2



« Posted 2014-05-13 15:14:36 »

Hey,

so im trying to add some Particles to my Game.
Ive done it according to the wiki and this post :
http://www.java-gaming.org/index.php?topic=29484.0
I get the Particles displayed where i want them, but i fail at rotating them.
I basicly have a function that Starts the Engine of the player, called by "w" for example.
in there i did the following :

 
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
PooledEffect effect = bombEffectPool.obtain();
                        effect.setPosition(sprite.getX(),sprite.getY());
                       
                        for (int j = 0; j < effect.getEmitters().size; j++) {
                           effect.getEmitters().get(j).getAngle().setLow(MathUtils.degreesToRadians * body.getRotation()); //low is the minimum rotation
                           effect.getEmitters().get(j).getAngle().setHigh(MathUtils.degreesToRadians * body.getRotation()); //high is the max rotation
                           effect.getEmitters().get(j).getRotation().setLow(sprite.getRotation());
                           effect.getEmitters().get(j).getRotation().setHigh(sprite.getRotation());
                            effect.update(Gdx.graphics.getDeltaTime());
                        }
                        effects.add(effect);

First i only did the rotation part in there, after that only the angle part, and now both, and no matter which of them i use, the particles doesnt rotate, not even a tiny bit.

they get draw with :
1  
2  
3  
4  
5  
6  
7  
8  
      for (int i = effects.size - 1; i >= 0; i--) {
          PooledEffect effect = effects.get(i);
          effect.draw(this.getSpriteBatch(), Gdx.graphics.getDeltaTime());
          if (effect.isComplete()) {
              effect.free();
              effects.removeIndex(i);
          }
      }


why is this happening ?
Offline trollwarrior1
« Reply #1 - Posted 2014-05-13 18:32:11 »

What does not rotating mean? Do they all go in the same direction, at rotation 0?

Do they go at rotated direction, but the sprite of displayed particle is not rotated? You're not being clear at all..
Offline ewg

Junior Duke


Medals: 8


Java games rock!


« Reply #2 - Posted 2014-05-13 18:58:45 »

Looks like you are converting to radians, I believe all angles should be in degrees.

Also if you set the high and low angles and rotations to the same value all particles will come out at the same angles and rotations.  You probably want to set a range between the high and low values.

in reference to the degrees instead of radians see this source code here:
https://github.com/libgdx/libgdx/blob/b706a25c4365fdf93e3efb6f28d7c9cd616278cc/extensions/gdx-tools/src/com/badlogic/gdx/tools/particleeditor/EffectPanel.java
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Buzzyboy
« Reply #3 - Posted 2014-05-14 03:38:39 »

Yes. The Particle Editor uses degrees. So I can only assume that everything involving it should also use degrees.

Offline T1663R

Junior Duke


Medals: 2



« Reply #4 - Posted 2014-05-14 07:59:32 »

thanks for your replys.
your right:
Body.getAngle()
should give me radians.  
but if i convert them to degrees:
1  
2  
                              effect.getEmitters().get(j).getAngle().setLow(MathUtils.radiansToDegrees*(body.getAngle()); //low is the minimum rotation
                           effect.getEmitters().get(j).getAngle().setHigh(MathUtils.radiansToDegrees*(body.getAngle()); //high is the max rotation

it still seems wrong.

ive got 2 sprite, with 2 body, connected together with a joint.
I need the particle to be "emitted" at the bottom of the left sprite. The sprite is 32px width, so is the particle spawn with.
Now as long as the Sprite doesnt rotate i somehow manage to get a result that may be ok, but if i rotate it the results look like this :




Offline ewg

Junior Duke


Medals: 8


Java games rock!


« Reply #5 - Posted 2014-05-14 15:50:14 »

I cannot really tell what is going on from those pictures.  I do not see two sprites or two bodies.  From your description it sounds like you are forgetting to convert your locally defined position and direction of into world space coordinates before setting the emitter's position and direction.   
Offline T1663R

Junior Duke


Medals: 2



« Reply #6 - Posted 2014-05-14 16:17:12 »

yeah sorry about the bad pics,there are some other sprites in the game that often block the view on those two sprites, so if i have this other stuff turned on the "problem" is alot harder to see, so i tryed to remove everything i can in order to make it somehow visible.
about the conversion, i do that right before the whole emitter thing :
1  
2  
3  
Vector2 d = new Vector2(body.getWorldPoint(new Vector2(0,-16)));
                        PooledEffect effect = bombEffectPool.obtain();
                        effect.setPosition(d.x,d.y);
Offline ewg

Junior Duke


Medals: 8


Java games rock!


« Reply #7 - Posted 2014-05-14 17:10:14 »

Can't help you just looking at these snippets.  I do not understand how you are updating the emitters position in both this new snippet and in the old one using different values.  Post the full code if you want help with it.
Offline T1663R

Junior Duke


Medals: 2



« Reply #8 - Posted 2014-05-15 09:59:14 »

the code in my snippets changed a little since ive tryed to fix it.
But ive always set the position in both cases before i did the rotation updates.
Heres the whole code as it looks atm :

 
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
                       startEngine();
                        Vector2 d = new Vector2(body.getWorldPoint(new Vector2(0,-16)));
                        PooledEffect effect = bombEffectPool.obtain();
                        effect.setPosition(d.x,d.y);
                        for (int j = 0; j < effect.getEmitters().size; j++) { //get the list of emitters - things that emit particles
                           effect.getEmitters().get(j).getAngle().setLow(MathUtils.radiansToDegrees*(body.getAngle()); //low is the minimum rotation
                           effect.getEmitters().get(j).getAngle().setHigh(MathUtils.radiansToDegrees*(body.getAngle()); //high is the max rotation
                           System.out.println(body.getAngle()  +  "    " +  MathUtils.radiansToDegrees * body.getAngle();
                           effect.getEmitters().get(j).getAngle().setActive(true);
                            effect.update(Gdx.graphics.getDeltaTime());
                        }
                        effects.add(effect);

Ive added a Debug Console output as you can see.
the console output gives me this right as i start to rotate:
1  
2  
0.0    0.0
-0.002368928    -0.13572957

and after a few complete rotations it gives me stuff like :
1  
-24.423641    -1399.3715

and this keeps increasing really fast.
Shouldnt it be 0-360  ? Im kinda stuck here.
Offline ewg

Junior Duke


Medals: 8


Java games rock!


« Reply #9 - Posted 2014-05-15 17:38:26 »

In the same way that you are converting your position from local to world coordinates you will have to convert the angle from local to world coordinates because the emitter is not at the origin of the local coordinates.

Box2d does not normalize the angles it returns to be within 1 rotation, if the number if greater than 1 rotation than it just means it has rotated multiple times.  If you really needed you could normalize the number, but I do not think it will matter here.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline T1663R

Junior Duke


Medals: 2



« Reply #10 - Posted 2014-05-15 18:29:47 »

In the same way that you are converting your position from local to world coordinates you will have to convert the angle from local to world coordinates because the emitter is not at the origin of the local coordinates.

if i lay a sprite exactly on top of the body. and do this :
1  
sprite.setRotation( MathUtils.radiansToDegrees*body.getAngle());

it stays exactly on the body and rotates along with it.
Also if i have other sprites and set these to this Rotation they also rotate exactly like this body, so imo that cant be the case.
Offline ewg

Junior Duke


Medals: 8


Java games rock!


« Reply #11 - Posted 2014-05-15 21:39:51 »

Oops think you are right, nothing to convert there.  You would only have to convert from local coords if you had a defined local emitter direction that needed to be combined with the rotation of the body it is connected to.  Post compilable/runnable code portions if you need help finding this bug.  I do not see it in the part here.
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (33 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (41 views)
2014-10-26 19:37:11

Luminem (22 views)
2014-10-26 10:17:50

Luminem (27 views)
2014-10-26 10:14:04

theagentd (33 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (59 views)
2014-10-16 15:22:06

Norakomi (47 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!