File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Particle System, always equals 0 ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Particle System, always equals 0 ?" Watch "Particle System, always equals 0 ?" New topic

Particle System, always equals 0 ?

Joshua Waring

Joined: Sep 04, 2012
Posts: 13
I'm trying to create my first particle system, when you click it creates a particle with addParticle at the position of the mouse click (LWJGL) and if the location of the particle (X,Y) fallse out of the range the index will be added to a stack which marks unused index's in the particles array so I can save space and reuse
but the problem is the cull, or maybe it's the add Particle, because the position is always being set to 0.0, EVEN THOUGH I've used a system.out.println to see the values given by Mouse.getX and it is working perfectly. That's the mind((()
Can someone please help.

Steve Luke

Joined: Jan 28, 2003
Posts: 4181

It looks to me like you are always filling in the information for the same particle: length is set to the value of ACT_PARTICLES as it stands at the beginning of the method call, and is not changed during the while loop. You do change the value of ACT_PARTICLES during the course of the while loop, but since length is a different variable it is a COPY when you first assign length = ACT_PARTICLES, so incrementing ACT_PARTICLES does not change the value of length. It seems to me like the first time the method is called, you assign to particles[0] (which you never test with the cull method). The second time you run the method you would assign all values to particles[n] where n is the number of particles added the first time the method was called. etc...

You also have this comment:

That isn't true. particles[0][0] will have the first particle's X position, not the particle count.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46349
Afraid I don’t understand the question, nor the code, which is difficult to read with the long lines (I split one in two) and the many commented‑out lines. Please have a look at some conventions about indenting and long lines (though those two conventions differ from each other in some places.

Please explain what you want to happen, and what is actually happen. You are not creating particles, because you don’t appear to have a Particle class. You are simply collecting numbers in an array. What are you using the stack for? Don’t use Stack, but use this.
I agree. Here's the link:
subject: Particle System, always equals 0 ?
It's not a secret anymore!