Page 1 of 1

Rain Effects?

PostPosted: Thu Sep 13, 2012 9:39 pm
by happyjustbecause
Is there anyway to have some kind of weather effects? I mainly want rain, but maybe snow too. Would there be the possibility of a large image looping through several lines or dots moving down?

How can I get this game's rain effect:

http://youtu.be/rJJNR6-TmmA?hd=1&t=1m20s

Re: Rain Effects?

PostPosted: Fri Sep 14, 2012 12:26 am
by skydereign
In Kid Krusader we used a large animation for rain, and one for snow. Your game has a rather large screen, so it is better not to use an animation for this if you can. I'd suggest creating a long strip of raindrops, and have it move to the bottom of the screen. When it reaches the bottom (out of vision event), warp it back to the top. You'll need to create several of these to have a full screen of rain, but it shouldn't slow down the game.

Re: Rain Effects?

PostPosted: Fri Sep 14, 2012 12:49 am
by happyjustbecause
Yeah that could work. I could also have them move at an angle (by having x and y movement). I'll experiment with that concept.

I didn't think that a large image would be a good idea, it would have to be a large image following the view too, causing more lag.

Re: Rain Effects?

PostPosted: Fri Sep 14, 2012 1:37 am
by happyjustbecause
Can you explain a good way on how to do the warp to the top?

Also, how would I prevent there being an empty area (no rain), if the rain isn't infinite.

Would you have the strips of raindrops be vertical or horizontal?

Re: Rain Effects?

PostPosted: Sat Sep 15, 2012 9:05 am
by skydereign
happyjustbecause wrote:Can you explain a good way on how to do the warp to the top?

I mentioned using the out of vision event in my previous post. That event triggers when an actor leaves the view (in your case rain moves to the bottom of the screen). When that happens you want to move it to the top of the screen. We know the view's position with view.x and view.y. So in the rain's out of vision event, all we need to do is set it relative to the view (if you remember xscreen and yscreen this can be done by just setting yscreen to a slightly negative number).

happyjustbecause wrote:Also, how would I prevent there being an empty area (no rain), if the rain isn't infinite.

When creating the rain, create it in such a way that it fills the screen (and a bit more). You can do something like this with a simple for loop.
Code: Select all
int i;
for(i=0;i<6;i++)
{
    // something along these lines
    CreateActor("rain", "rain", "(none)", "(none)", view.x, view.y-20+i*50, true);
}


happyjustbecause wrote:Would you have the strips of raindrops be vertical or horizontal?

Horizontal strips if you don't want to use an animation.

Re: Rain Effects?

PostPosted: Sat Sep 15, 2012 3:47 pm
by happyjustbecause
How can I have the rain follow the view? I tried parenting the rain to the view, and I can't just put x=view.x and y=view.y, because that doesn't allow for movement of the rain.

And sorry I should have mentioned what I meant for the warp. If I want to have x and y movement of the rain, how can I make it so that the rain doesn't just warp all into the same place? I just think the rain may look better moving at a slight angle.

Re: Rain Effects?

PostPosted: Wed Sep 19, 2012 10:08 pm
by skydereign
happyjustbecause wrote:How can I have the rain follow the view?

Why doesn't parenting work in this case?
happyjustbecause wrote:I can't just put x=view.x and y=view.y, because that doesn't allow for movement of the rain.

You can use an offset variable, though it wouldn't be necessary as parenting should work.
happyjustbecause wrote:If I want to have x and y movement of the rain, how can I make it so that the rain doesn't just warp all into the same place? I just think the rain may look better moving at a slight angle.

You can warp the rain back to the top of the view, relative to where the actor is. You know its xvelocity, yvelocity, and how tall the view is. With that, you can determine how far (in x) the rain was offset, reverse it, and set the y to above the view.

Re: Rain Effects?

PostPosted: Wed Sep 19, 2012 11:39 pm
by happyjustbecause
Oh, I forgot that I need to make all the clones parented to the view. I'll just put that in the create actor.

Re: Rain Effects?

PostPosted: Thu Sep 20, 2012 12:10 am
by happyjustbecause
You can warp the rain back to the top of the view, relative to where the actor is. You know its xvelocity, yvelocity, and how tall the view is. With that, you can determine how far (in x) the rain was offset, reverse it, and set the y to above the view.


Well, how exactly can I do that? I'm not sure what you mean by reverse it. I got the parenting to work now.

Re: Rain Effects?

PostPosted: Thu Sep 20, 2012 7:08 am
by skydereign
It's essentially a triangle. You know the xvelocity and yvelocity which are loosely the width and height of the triangle (the hypotenuse is the path it took). You can find the exact x and y width/height by finding the time it fell from top to bottom (using yvelocity and the height of the view).

From the equation, v=d/t, we can figure out time (t=d/v). Distance is view.height plus the safe margin and v is yvelocity. Now we already knew how far to move the actor up (just the height of the view plus a little bit to make it smooth), but we needed to know how much it moved from the top. We can now use d=vt, with v being xvelocity, to find how much it has moved left or right. More specifically xdist = xvelocity*((view.height+safe_margin)/yvelocity).

actor -> Out of Vision -> Script Editor
Code: Select all
if(yscreen>view.height) // prevents out of vision event for left and right screen
{
    yscreen = -20; // half the safe margin
    xscreen -= xvelocity*((view.height+40)/yvelocity);
}

The use of xscreen and yscreen is to prevent any problems with parenting problems.

Now this can potentially be avoided (no need to calculate the position to jump back to) by either recording the original position (and creating the rows over a certain number of frames), or doing the calculations before hand, and hard coding them in. You could even create global variables to hold the offsets that way you don't have to have the actors recalculate it every time.
view -> Create Actor -> Script Editor
Code: Select all
y_offset = -20; // half the safe margin
x_offset = 2*((height+40)/10); // same equation as the previous code
// just replaced xvelocity and yvelocity (can use defines or variables as well)

That way you can just use yscreen-=y_offset and xscreen-=x_offset.

Re: Rain Effects?

PostPosted: Thu Sep 20, 2012 7:56 pm
by happyjustbecause
Oh, cool thank you, the rain now looks even better moving at a slight angle.

But there is one issue I'm unsure on how to fix. When the view moves up because of the player jumping, the rain looks like it is slowing down it's velocity. And the same kind of thing happens when the view moves down as the player is falling, the rain starts traveling extremely quickly. Is there some way to have the velocity balance out with the view movement? Some way to make the rain look like it acts on its own, not affected by the movement of the view.

And this isn't completely on subject, but it has to do with implementing the rain.

I added a sound for the rain, and I was wondering on how I can make it so that the rain's sound is playing and looping as long as it the rain is going on? I guess I could have a switch statement seeing if there are any rain actors present, or maybe I can check the visibility state? But I also just want to know how to have a sound loop forever (as long as rain is present), or do I just choose an amount that would be going on a long time?

I mention check the visibility state, because I don't want rain constantly going on, but I'm not sure how I would get rid of it and have it appear again, being in the same orientation, allowing for the safe margins and such.

Also, since I have in the options menu the ability to change the sound effect's volume, is there anyway I would be able to do that while it is playing, it is smoothly loopable, so would I have to just replay the sound when changing the volume?

Re: Rain Effects?

PostPosted: Thu Sep 20, 2012 8:41 pm
by skydereign
happyjustbecause wrote:But there is one issue I'm unsure on how to fix. When the view moves up because of the player jumping, the rain looks like it is slowing down it's velocity. And the same kind of thing happens when the view moves down as the player is falling, the rain starts traveling extremely quickly. Is there some way to have the velocity balance out with the view movement? Some way to make the rain look like it acts on its own, not affected by the movement of the view.

To do this, you'd need to give your rain particle a draw event or create a larger grid of rain (and create a different out of vision event). Neither is really recommended. Now this actual problem is because you parented it to the view.

happyjustbecause wrote: I guess I could have a switch statement seeing if there are any rain actors present, or maybe I can check the visibility state?

A switch statement?
Code: Select all
switch(ActorCount("rain"))
{
    case 0:
    break;

    default:
    // play sound
    break;
}

At that point you should just use an if statement. As for checking visibility state, you can't in the current version of gE.

happyjustbecause wrote:I mention check the visibility state, because I don't want rain constantly going on, but I'm not sure how I would get rid of it and have it appear again, being in the same orientation, allowing for the safe margins and such.

You could set it up for the rain to be parented to a wire frame region the size of the view, and have the wireframe parented to the view. This way you can disable the wireframe's visibility state to disable all of the rain particles as well (you'll also want to event disable the wireframe). Using this will also solve your rain sound problem, as in its draw actor, you can loop the sound effect. It won't trigger when rain is disabled as all of its events are disabled.

happyjustbecause wrote:is there anyway I would be able to do that while it is playing, it is smoothly loopable, so would I have to just replay the sound when changing the volume?

You are replaying the sound anyways, right? So this shouldn't be an issue, unless it is a lengthy wav. In which case yes, just replay the sound with the new volume.

Re: Rain Effects?

PostPosted: Thu Sep 20, 2012 10:53 pm
by happyjustbecause
I added the wireframe region, but when the visibility state is changed for the wireframe region, it doesn't change it's child actor's visibility state. And the EventDisable doesn't affect the child actor.

I'm trying to fix the sound effect, but when I put in the draw actor of the wireframe (<-- maybe you meant the rain actor?), it just sounds like it's playing the same sound effect constantly, like white noise almost.

This is the code for the wireframe (parent of rain)

Code: Select all
if(RainOn==0)
{
    VisibilityState("Event Actor", DONT_DRAW_ONLY);
    VisibilityState("Rain", DONT_DRAW_ONLY);
    EventDisable("Rain", EVENTALL);
    EventDisable("Event Actor", EVENTALL);
}
else
{
    VisibilityState("Event Actor", ENABLE);
    VisibilityState("Rain", ENABLE);
    EventEnable("Event Actor", EVENTALL);
    EventEnable("Rain", EVENTALL);
    PlayMusic2("data/Rain.ogg", SFX_Volume, 0, HIGH_PRIORITY_MUSIC);
}


I want to have the RainOn variable that way I have an easy way to turn the rain on/off.

How can I make the sound play through okay?
The rain sound effect is around 30 seconds, did you think it was only a couple seconds? Or am I missing something?

Re: Rain Effects?

PostPosted: Fri Sep 21, 2012 6:21 am
by skydereign
happyjustbecause wrote:I added the wireframe region, but when the visibility state is changed for the wireframe region, it doesn't change it's child actor's visibility state. And the EventDisable doesn't affect the child actor.

You must be doing something wrong. Try testing it in a new game to see that it works, and then try it in yours.

happyjustbecause wrote:I'm trying to fix the sound effect, but when I put in the draw actor of the wireframe (<-- maybe you meant the rain actor?), it just sounds like it's playing the same sound effect constantly, like white noise almost.

You without a doubt should not put it in the rain actor. While I get why you might think of putting it in the rain actor, think of it this way. You have several rain actors, for this argument I'll say eight of them. If each of them have the code in the draw event, then you have it playing new rain noises eight times per frame.

Now, you said your sound effect is 30 seconds long. So, knowing that it is supposed to be in the wireframe (where there is only one actor), why would you want it to trigger every frame? You only want it to play once every 30 seconds, which is 900 frames assuming you haven't changed the game's fps. I would use a variable timer in the draw event to play the sound only once every 30 seconds. But looking at your code, you aren't even using sound effects. You are using the PlayMusic2 function, which means there can't be any music in your game while the rain is active. But because you are using PlayMusic you can use the built in way of repeating it (by setting the number of times to play it to 0). And to stop it you use stopSound(1) since music is always in the first channel.

happyjustbecause wrote:I want to have the RainOn variable that way I have an easy way to turn the rain on/off.

Use a function. Your current code is in the draw actor, which means it triggers every frame, retelling the game. And even then your code won't work, because it disables the draw event. Which means it will never see that RainOn switched. Using a function to toggle it allows you to only call it once, and unlike your variable, the game really only needs to be told once.

Re: Rain Effects?

PostPosted: Sat Sep 22, 2012 1:08 am
by happyjustbecause
Oh, I didn't know there could only be one music track being played. I think I did that because the file was ogg. I'll just convert it, and also shorten it to make the file size reasonable.

I added the timer to the draw actor and everything works, except now there is a 5 second pause before the sound starts playing (when the game initializes). I tried adding the playsound to the create actor of the rainparent actor, but that didn't work for some reason.

I'll try out making the RainOn function. Though, I'm not really experienced in making functions yet.