Question

So I am using the Slick2D particle system for some effects in my game, and it worked pretty good so far. But now I found out that the very first wave of particles being spawned is always misplaced for me, exactly twice the distance it should be (x and y). I tried it with different XML sheets but it continues to happen, no matter what specifications I use. I of course looked it up on the Internet then, but it looks like nobody had this problem yet :/ Then I took a look at that tutorial I started with (http://www.youtube.com/watch?v=Re5XJiWy4eQ, it's really good) and in that video, I am pretty sure, there is no misplacement on the first spawn. In that videos description is a download for the files used in this video, so I downloaded them and tried it out, but for me there is that misplacement thingy again. It only happens on first wave of particles spawning, all the others after that spawn right where they are supposed to.

Here is an example of the XML sheets I tried:

<?xml version="1.0" encoding="UTF-8"?>
<emitter imageName="" name="Test Particle">
  <spawnInterval enabled="true" max="500" min="100"/>
  <spawnCount enabled="true" max="2" min="0"/>
  <initialLife enabled="true" max="1000.0" min="1000.0"/>
  <initialSize enabled="true" max="15" min="8"/>
  <xOffset enabled="true" max="5.0" min="-5.0"/>
  <yOffset enabled="true" max="10.0" min="-10.0"/>
  <initialDistance enabled="true" max="0.0" min="0.0"/>
  <speed enabled="true" max="140.0" min="0.0"/>
  <length enabled="true" max="2500.0" min="1500.0"/>
  <spread value="75.0"/>
  <angularOffset value="0.0"/>
  <growthFactor value="13.0"/>
  <gravityFactor value="3.7"/>
  <windFactor value="1.0"/>
  <startAlpha value="50.0"/>
  <endAlpha value="0.0"/>
  <color>
    <step b="1.0" g="1.0" offset="0.0" r="1.0"/>
    <step b="1.0" g="1.0" offset="1.0" r="1.0"/>
  </color>
</emitter>

Thank you for your help in advance :)

Was it helpful?

Solution

After reviewing the source code (and not being on my phone), I found that there are two methods that ConfigurableEmitter class has that are setPosition related.

setPosition(float x, float y):

this method calls setPosition(x, y, true); which sends a true value to the actual setPosition() method.

setPosition(float x, float y, boolean moveParticle):

this tells the emitter to show up relative to where the particle was placed (which causes the doubled position because the particle is already set to that position to begin with).

How to fix your problem:

If you want to have the emitter set to the right position, just call configEmitter.setPosition(x, y, false);

OTHER TIPS

In the Java program add a third parameter to emitter.setPosition() and set it to false like this for example. emitter.setPosition(500,500, false);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top