Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 27, 2018 1:20 pm

All times are UTC

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Rotating Emitter
PostPosted: Sun Jan 02, 2011 8:43 pm 

Joined: Sun Jan 02, 2011 7:52 pm
Posts: 13
Hi Community,
last week I've stated with slick.
I want to rotate a ParticleSystem or the Emitter in it. In an other slick thread i got the information that i must rotate the graphics object.

If the plane stands still the particle rotates with the plan everything is fine.
But if i move the plane the particles flying is very crazy

Here a Screenshot:


Here the sourcecode:
package slick.path2glory.tutorial1;

import java.awt.Point;

import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Circle;
import org.newdawn.slick.geom.Line;
import org.newdawn.slick.particles.ConfigurableEmitter;
import org.newdawn.slick.particles.ParticleIO;
import org.newdawn.slick.particles.ParticleSystem;

public class SlickBasicGame extends BasicGame {

   Image plane = null;
   Image background = null;
   Image sword = null;
   ConfigurableEmitter space_shuttle_emitter;
   ParticleSystem particleSystem;

   float x;
   float y;
   float r;
   float mx;
   float my;
   float moveX;
   float moveY;
   public SlickBasicGame() {
      super("Slick2D Path2Glory - SlickBasicGame");

   public void init(GameContainer gc) throws SlickException {
      plane = new Image("testdata/shuttle.gif");
      background = new Image("data/bg.png");

      r = plane.getHeight() / 2;
      try {
         space_shuttle_emitter = ParticleIO.loadEmitter("emitter/space_shuttle_trail.xml");
         particleSystem = new ParticleSystem("testdata/smoke.tga");
      } catch (IOException e) {

   public void update(GameContainer gc, int delta) throws SlickException {
      Input input = gc.getInput();

      if (input.isKeyDown(Input.KEY_A)) {
         plane.rotate(-0.1f * delta);

      if (input.isKeyDown(Input.KEY_D)) {
         plane.rotate(0.1f * delta);

      if (input.isKeyDown(Input.KEY_W)) {
         float hip = 0.4f * delta;

         float rotation = plane.getRotation();

         x += hip * Math.sin(Math.toRadians(rotation));
         y -= hip * Math.cos(Math.toRadians(rotation));

      if (input.isKeyDown(Input.KEY_2)) {
         plane.setCenterOfRotation(plane.getWidth() / 2.0f,
               plane.getHeight() / 2.0f);
      if (input.isKeyDown(Input.KEY_1)) {
         plane.setCenterOfRotation(plane.getWidth() / 2.0f,
               plane.getHeight() / 2.0f);
      mx = x + plane.getWidth()/2;
      my = y + plane.getHeight()/2;
      moveX = (float)Math.cos(plane.getRotation()) * r;
      moveY = (float)Math.sin(plane.getRotation()) * r;
      ((ConfigurableEmitter) particleSystem.getEmitter(0)).setPosition(mx,my,false);

   public void render(GameContainer gc, Graphics g) throws SlickException {
      background.draw(0, 0);
      plane.draw(x, y);
      g.draw(new Circle(mx, my, plane.getHeight() / 2));
      g.rotate(mx, my, plane.getRotation());


THX for any help

 Post subject:
PostPosted: Sun Jan 02, 2011 8:49 pm 
User avatar

Joined: Fri Jul 20, 2007 9:25 am
Posts: 410
Location: Croatia
you can rotate the emitter by setting it's angle property. This will only work if your emitter is in the center of the ship, if it's placed into the back of the ship (like engines at back) you will need to reposition it also. Best if you create your emitter so it emits from the center.

Also, I did not try manipulating graphic context with g.rotate() before rendering particles so I do not know if it will work, but rotating everything around the center of the ship before rendering emitter and resting back afterwords might work and would be easiest solution I guess.

 Post subject:
PostPosted: Sun Jan 02, 2011 9:39 pm 

Joined: Sun Jan 02, 2011 7:52 pm
Posts: 13
thx for reply, and how do i edit the value of the angle..

((ConfigurableEmitter) particleSystem.getEmitter(0))...?....



I found it



Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group