particles.lua help (again)

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

Hammerless Penguin
Snifit
Snifit
Posts: 203
Joined: Sat Sep 22, 2018 6:17 am
Flair: Just kicking that kirby to the curb!
Contact:

particles.lua help (again)

Postby Hammerless Penguin » Sun Jan 19, 2020 10:50 pm

I'm trying to make certain npcs leave trails of smoke and fire as they move but i'm not sure how to make npcs do that. I've seen this been done before but I still don't know how to do it.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: particles.lua help (again)

Postby Emral » Mon Jan 20, 2020 1:10 am

Here's step-by-step how most people do this:
1) Make an empty table which you will use for all emitters that have been spawned. This list will be responsible for drawing the emitters. People don't use NPC code for drawing emitters because when the NPC dies, that just means all the particles will also die instantly as they no longer get drawn.
2) In onDraw, loop over the list and call :Draw(priority) on every emitter to make sure it draws.
3) Time to populate the list! In your for loop over your NPCs, wrap the NPC in pnpc and then, if v.data.emitter is nil, set it to a new emitter of the file you wish to use.
4) Remember to call v.data.emitter:Attach(v) to make the emitter move with the NPC, and to insert v.data.emitter into the emitter table for drawing.
For the last part, there are two ways to go about it. You have to stop spawning particles when the NPCs die.
5a) Set the rate of your emitter to 0 and manually spawn particles in the NPC tick function using v.data.emitter:Emit(amount).
5b) Assign v.data.emitter.enabled = false when the NPC dies in onNPCKill

Hammerless Penguin
Snifit
Snifit
Posts: 203
Joined: Sat Sep 22, 2018 6:17 am
Flair: Just kicking that kirby to the curb!
Contact:

Re: particles.lua help (again)

Postby Hammerless Penguin » Mon Jan 20, 2020 7:42 am

Enjl wrote:
Mon Jan 20, 2020 1:10 am
Here's step-by-step how most people do this:
1) Make an empty table which you will use for all emitters that have been spawned. This list will be responsible for drawing the emitters. People don't use NPC code for drawing emitters because when the NPC dies, that just means all the particles will also die instantly as they no longer get drawn.
2) In onDraw, loop over the list and call :Draw(priority) on every emitter to make sure it draws.
3) Time to populate the list! In your for loop over your NPCs, wrap the NPC in pnpc and then, if v.data.emitter is nil, set it to a new emitter of the file you wish to use.
4) Remember to call v.data.emitter:Attach(v) to make the emitter move with the NPC, and to insert v.data.emitter into the emitter table for drawing.
For the last part, there are two ways to go about it. You have to stop spawning particles when the NPCs die.
5a) Set the rate of your emitter to 0 and manually spawn particles in the NPC tick function using v.data.emitter:Emit(amount).
5b) Assign v.data.emitter.enabled = false when the NPC dies in onNPCKill
Im still a bit confused. Can you give me an example code on how to assemble all of this?


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 3 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari