[4.5.9] Simple light-weight Rain

9Panzer

Well-known member
So I've been wanting to do add some simple effects to my next build and wanted to dive deeper into sprites. one of the challenges we have is that the NESmaker object system is quite Resource intensive so doing fun little animations using objects tends to not work well beyond 4 or 5 objects.


This code is very simple and doesn't use the object system at all. Instead it just tells the game to draw the sprite on the screen with no collision checks, size checks, etc... so you can use it without gimping your game.

1. First make a pair of Variables. I used "Object Variables" instead of "User Variables" for this as the User Variables didn't refresh quick enough for the rain to be nice and smooth. The Variables I used in this example are "RainingV" and "RainingH".

2. Open your "doSpritePreDraw" (Or Postdraw depending on if you want them rain infront or behind). and put this code in:

LDA RainingH
SBC camX ;When Scrolling - to make the rain move correctly
STA temp1
LDA RainingV
STA temp2
DrawSprite temp1, temp2, #111, #%00000001

LDA RainingH
ADC #40
SBC camX ;When Scrolling - to make the rain move correctly
STA temp1
LDA RainingV
ADC #100
STA temp2
DrawSprite temp1, temp2, #111, #%00000001


LDA RainingH
ADC #90
SBC camX ;When Scrolling - to make the rain move correctly
STA temp1
LDA RainingV
ADC #90
STA temp2
DrawSprite temp1, temp2, #111, #%00000001

LDA RainingH
ADC #130
SBC camX ;When Scrolling - to make the rain move correctly
STA temp1
LDA RainingV
ADC #180
STA temp2
DrawSprite temp1, temp2, #111, #%00000001


LDA RainingH
ADC #200
SBC camX ;When Scrolling - to make the rain move correctly
STA temp1
LDA RainingV
ADC #200
STA temp2
DrawSprite temp1, temp2, #111, #%00000001

For this example I have used the 111 sprite on your objects.

3. add this to your timer script (add more if you want faster rain)
DEC RainingH
DEC RainingH
DEC RainingH

Inc RainingV
Inc RainingV
Inc RainingV

That's it! Enjoy your raining game!
 

Bucket Mouse

Active member
Thanks for posting this -- I've long wondered how to get rain working. This will work on both scrolling and non-scrolling modules, right?
 

SciNEStist

Well-known member
you could also alter the angle by changing the ratio of "DEC RainingH" and "Inc RainingV" if you dont want it to be 45 degrees all the time
 

DocNES

Member
This is amazing! Just what I was looking for. Have some cool ideas written down just for this already :)
Had to add mine to Handle Game Time.
 

tbizzle

Well-known member
*Edit - Nevermind, just taught myself how to use screenflags , lol.

@9Panzer How do we control this to only be used on certain screens???
 
Last edited:

SciNEStist

Well-known member
I go with a userscreenbyte so i can pick multiple forms of weather.

Not sure if Object Variables is the best way to go for making the x/y variables, since that creates 2 new variables for every active object at any time.
 

9Panzer

Well-known member
I go with a userscreenbyte so i can pick multiple forms of weather.

Not sure if Object Variables is the best way to go for making the x/y variables, since that creates 2 new variables for every active object at any time.
When I used UserVariables It glitched out bad and actually crashed it alot of the times.
 

vanderblade

Active member
Works like a charm, Dave. Thanks! As I move towards a Kickstarter for my brawler Leggite Luta Livre, these are the small details that help plus the game just a little more. It's weird to have been working on the game off and on since early 2021. Each time I return, something gets improved. Hoping to put it to rest forever soon.
 

BITVADER

Member
Just a quick question, is it possible for this script to rain objects instead of sprite pieces?
(I want to use CreateObjectOnScreen instead of using DrawSprite)
 

dale_coop

Moderator
Staff member
If you want to use objects (with CreateObjectOnScreen) I'd suggest to use a timer...
But, keep in mind that you will encounter slowdowns issues, when there will be more than 4 or 5 objects on screen at the same time.
 

9Panzer

Well-known member
Just a quick question, is it possible for this script to rain objects instead of sprite pieces?
(I want to use CreateObjectOnScreen instead of using DrawSprite)
You could, but the entire point of using the drawSprite instead of CreateObject is to keep the CPU cycles as low as possible. NESmaker can generally only push out 4-6 objects depending on the Modules and modifications you've made. If you use the way I've setup you will still be able to use the objects.
 

BITVADER

Member
Thanks dale and 9Panzer.
I heard this because I wanted to express the fluttering cherry blossom petals in a certain scene.
If the problem is that the load is too much, it's good to know that there are ways to reduce the load (narrow down the number of petals represented by CreateObject to one or two and use DrawSprite for the rest).
 

dale_coop

Moderator
Staff member
Or you could draw alternatively one sprite then another one... to simulate the animation of the petals.
 
Top Bottom