Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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 to create a rain and cloud? (Using "Particle")  (Read 1645 times)
0 Members and 1 Guest are viewing this topic.
Offline michel.montenegro

Senior Newbie





« Posted 2014-01-02 04:48:39 »

How to create the effect of rain?
How to create the effect of cloud across the map?
Note: If using Particle possible!

Below is the full code that generates these particles on the screen.
Did you do the rainfall and cloud moving horizontally alert Particle if possible.

Otherwise what would be another outlet for this problem?



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
package project.parallax;

import project.parallax.actor.Hero;
import box2dLight.PointLight;
import box2dLight.RayHandler;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.ParticleEmitter;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Array;

public class LightRenderer {
  private RayHandler rayHandler;
  private OrthographicCamera camera;
  private PointLight playerLight;
  private Hero player;
  private ParticleEffect effect;
  private Vector2 positionLight = new Vector2();
  private BodyDef tileBodyDef;
  private World lightWorld;
  private FixtureDef fixtureDef;
  private PolygonShape tileShape;


  public LightRenderer(OrthographicCamera camera, Hero player) {
    this.camera = camera;
    this.player = player;

    lightWorld = new com.badlogic.gdx.physics.box2d.World(new Vector2(), true);

    RayHandler.useDiffuseLight(true);
    this.rayHandler = new RayHandler(lightWorld);
    this.rayHandler.setCombinedMatrix(this.camera.combined);
   
    int distanceLight = 96;
    playerLight = new PointLight(rayHandler, 128, new Color(0.8f,0.8f,0.8f,0.6f), distanceLight, 510, 385);
   
    // Create a shape that casts a shadow
   PolygonShape tileShape = new PolygonShape();
    tileShape.setAsBox(5.5f, 5.5f);

    tileBodyDef = new BodyDef();
    tileBodyDef.type = BodyType.StaticBody;

    fixtureDef = new FixtureDef();
    fixtureDef.shape = tileShape;
    fixtureDef.filter.groupIndex = 0;

    tileBodyDef.position.set(510, 385);
    effect = new ParticleEffect();
    effect.load(Gdx.files.internal("data/test.p"),Gdx.files.internal("data/"));
    Array<ParticleEmitter> emitters = new Array<ParticleEmitter>(effect.getEmitters());
    effect.getEmitters().clear();
    effect.getEmitters().add(emitters.get(3));    
    effect.start();
    //tileShape.dispose();
 }
 
  SpriteBatch sb = new SpriteBatch();
  public void drawBlasts(){
     
     effect.setPosition(300, 300);
     sb.begin();
     effect.draw(sb, Gdx.app.getGraphics().getDeltaTime());
     sb.end();
   }  
 
  /**
   * Cria uma so~mbra,como se estivesse segurando uma vela.
   */

  public void addEffectShadow(){
    Body tileBody = lightWorld.createBody(tileBodyDef);
    tileBody.createFixture(fixtureDef);
  }

  public void setAmbient(Color color) {
    this.rayHandler.setAmbientLight(color);
  }

  public void render() {
   this.positionLight.set(this.player.getX(), this.player.getY());
    this.playerLight.setPosition(positionLight);
    this.rayHandler.setCombinedMatrix(this.camera.combined);
    this.rayHandler.updateAndRender();
  }

  public void dispose() {
    rayHandler.dispose();
    tileShape.dispose();
  }

   public PointLight getPlayerLight() {
      return playerLight;
   }
   
   public void setPlayerLight(PointLight playerLight) {
      this.playerLight = playerLight;
   }
   
}


Test.p
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
smoke
- Delay -
active: false
- Duration -
lowMin: 1.0
lowMax: 1.0
- Count -
min: 0
max: 1000
- Emission -
lowMin: 0.0
lowMax: 0.0
highMin: 3.0
highMax: 3.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Life -
lowMin: 0.0
lowMax: 0.0
highMin: 3000.0
highMax: 3000.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Life Offset -
active: false
- X Offset -
active: false
- Y Offset -
active: false
- Spawn Shape -
shape: square
- Spawn Width -
lowMin: 0.0
lowMax: 0.0
highMin: 180.0
highMax: 800.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Spawn Height -
lowMin: 0.0
lowMax: 0.0
highMin: 110.0
highMax: 6000.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Scale -
lowMin: 0.0
lowMax: 0.0
highMin: 256.0
highMax: 256.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Velocity -
active: true
lowMin: -25.0
lowMax: -25.0
highMin: 25.0
highMax: 25.0
relative: false
scalingCount: 2
scaling0: 0.0
scaling1: 1.0
timelineCount: 2
timeline0: 0.0
timeline1: 1.0
- Angle -
active: true
lowMin: 0.0
lowMax: 0.0
highMin: 1.0
highMax: 360.0
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0
- Rotation -
active: true
lowMin: 1.0
lowMax: 360.0
highMin: -30.0
highMax: 30.0
relative: true
scalingCount: 2
scaling0: 0.0
scaling1: 1.0
timelineCount: 2
timeline0: 0.0
timeline1: 1.0
- Wind -
active: false
- Gravity -
active: false
- Tint -
colorsCount: 6
colors0: 1.0
colors1: 0.0
colors2: 0.0
colors3: 1.0
colors4: 0.9843137
colors5: 0.0
timelineCount: 2
timeline0: 0.0
timeline1: 1.0
- Transparency -
lowMin: 0.0
lowMax: 0.0
highMin: 1.0
highMax: 1.0
relative: false
scalingCount: 3
scaling0: 0.0
scaling1: 0.49122807
scaling2: 0.0
timelineCount: 3
timeline0: 0.0
timeline1: 0.5068493
timeline2: 1.0
- Options -
attached: false
continuous: true
aligned: false
additive: true
behind: false
- Image Path -
particle-cloud.png


effect rain:
Click to Play
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2014-01-02 04:51:14 »

Sorry, but what is your question?

Offline michel.montenegro

Senior Newbie





« Reply #2 - Posted 2014-01-02 04:54:45 »

How to create the effect of rain?
How to create the effect of cloud across the map?
Note: If using Particle possible!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #3 - Posted 2014-01-02 04:58:42 »

Ok, this is way too broad of a question. What you need to do is start off with basic particles and work your way up. No one is going to just give you pages upon pages of code.

Offline michel.montenegro

Senior Newbie





« Reply #4 - Posted 2014-01-02 05:09:00 »

The question was straightforward and simple!
And there's also simple and direct answer.

But as I'm redoing the project in LibGDX, like intelligent and straightforward opinions on the subject.
If possible show with code or ready examples would be wonderful! (And I particularly like other would be grateful).

My project, and free and open-source (source-forge), then all progress on the project and directly passed on to the community.

There are several ways to do this until I talked to the guys here a long time ago.
See Link:
http://www.java-gaming.org/topics/slick2d-how-to-create-a-rain-and-snow/26424/msg/231818/view.html#msg231818


Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #5 - Posted 2014-01-02 05:11:07 »

So why not follow those tutorials if you already have the answer?

Like I said, no one is going to just give you code without more explanation of your problem, or you telling us what you've already done.

Offline michel.montenegro

Senior Newbie





« Reply #6 - Posted 2014-01-02 05:21:40 »

Good, let's start.

I was going to rain as follows:
Various actors in a "Stage" falling vertically, being drawn randomly on the screen. (But it has a higher cost in processing and memory)

I made a simple example with particle (to whom I sent screen and full class code in the 1st post), and I realized that maybe used for particle effects:
rain
Cloud passing horizontally
mist
Sandstorm
thunder

Particles would be more interesting with, so I decided to just ask about the rain and it aparti have mold to see how would the other effects.
Online Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #7 - Posted 2014-01-02 05:30:36 »

Various actors in a "Stage" falling vertically, being drawn randomly on the screen. (But it has a higher cost in processing and memory)
Obviously this is a terrible idea because of the reasons you mentioned; the lesson is that generally you should use whatever libgdx provides you (and it provides you with a lot). You don't necessarily need a particle emitter for a cloud, can't you just use a cloud image? Same with the sandstorm, unless you want a particle for each grain of sand (even simplified, I'm not really seeing it here). For lightning, unless you want it to be truly random/particle behavior, you're probably better off using an animation. Rain is a good use for particles, but you don't necessarily need them: http://gamedev.stackexchange.com/questions/35415/how-to-create-a-raining-effectparticles-on-android - first answer provides a link to a good method.
Offline michel.montenegro

Senior Newbie





« Reply #8 - Posted 2014-01-02 05:55:00 »

I had seen this link, but did not quite understand his explanation.

As I understand it creates 10 images on the screen and stretches them vertically. Then back to normal size and keep doing that for a while, my understanding is correct? or it just toggles between visible (true and false), creating an optical illusion (Giving the idea that they are falling)?

Any link or picture with something similar to that to think about the effect of cloud and Sandstorm?
Online Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #9 - Posted 2014-01-02 06:02:22 »

I had seen this link, but did not quite understand his explanation.

As I understand it creates 10 images on the screen and stretches them vertically. Then back to normal size and keep doing that for a while, my understanding is correct? or it just toggles between visible (true and false), creating an optical illusion (Giving the idea that they are falling)?

Any link or picture with something similar to that to think about the effect of cloud and Sandstorm?
Rain falls to fast to see individual particles, so just drawing a line like that in 2d actually works fairly well; you just draw it at random angles and locations within a threshold.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline michel.montenegro

Senior Newbie





« Reply #10 - Posted 2014-01-02 14:07:21 »

The video below is version 2.0 of my project, jumps to the 01:00 time +, there has the following effects:
1. Cloud moving horizontally.
2. Sandstorm.
3. Rain.

Item 1 and 2 I made a giant image that moves vertically to a point and restarts again.
Note: Would have any idea or better and performative suggestion for items 1 and 2?

Item 3 I draw several rectangles and let falling (Alternate only the expessura of it)
<a href="http://www.youtube.com/v/2vc7KPJJZ00?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/2vc7KPJJZ00?version=3&amp;hl=en_US&amp;start=</a>
Do you know a website with pre particles ready? (You may also pay site).
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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 (11 views)
2014-08-28 18:26:30

CopyableCougar4 (24 views)
2014-08-22 19:31:30

atombrot (37 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (29 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (33 views)
2014-08-08 02:01:56
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59: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!