particle script helper

A place for developers to promote games they have created with Moai

particle script helper

Postby tommo.zhou » Sun Oct 23, 2011 3:23 pm

I wrote a particle script helper for MOAI to help write readable particle script.

Source code here:

http://pastebin.com/feWDLXyT



Example here (based on samples/basic/distanceEmitter.lua):

http://pastebin.com/NbhKzXHu



I'd be happy if someone find it useful.Cool
tommo.zhou
 
Posts: 81
Joined: Thu Sep 29, 2011 12:28 am

particle script helper

Postby patrick » Mon Oct 24, 2011 4:20 am

That's awesome!

Would love to ship this with the SDK. Can you add a licensing note at the top, maybe MIT license or something similar? If you do that I'll grab a copy and include it w/ the next release. Will also grab a copy for the wiki.

(Also: would you like a login to be a wiki contributor? Still looking for volunteers...)
User avatar
patrick
 
Posts: 589
Joined: Sat Apr 02, 2011 10:50 pm

particle script helper

Postby tommo.zhou » Mon Oct 24, 2011 3:17 pm

Copyright header added (MIT).

But I found that only the first register can be shared properly across init/render scripts. Maybe it's a bug?

I'd like to contribute to the wiki,  how can I register?
tommo.zhou
 
Posts: 81
Joined: Thu Sep 29, 2011 12:28 am

particle script helper

Postby patrick » Tue Oct 25, 2011 11:59 am

Nice!

Todd will send you a wiki login.

Re the register bug, I haven't looked closely but off the top of my head... when you call reserveParticles the second number is the total number of registers that get allocated for each particle. So if you have a '1' there, then the particle will only remember the contents of the first register from call to call (and between scripts). Try using a bigger number. If that doesn't fix it I will set some time aside to troubleshoot it tomorrow or the next day.
User avatar
patrick
 
Posts: 589
Joined: Sat Apr 02, 2011 10:50 pm

particle script helper

Postby tommo.zhou » Tue Oct 25, 2011 6:06 pm

Ok, that fix the problem. Sorry for not reading doc carefully.Laugh
tommo.zhou
 
Posts: 81
Joined: Thu Sep 29, 2011 12:28 am

particle script helper

Postby patrick » Tue Oct 25, 2011 6:18 pm

Great!
User avatar
patrick
 
Posts: 589
Joined: Sat Apr 02, 2011 10:50 pm

particle script helper

Postby mikea » Wed Oct 26, 2011 9:42 am

Tommo - email me at "mike" "at" "ziplinegames" "dot" "com" and I'll get you set up with a wiki account.
mikea
 
Posts: 34
Joined: Fri Mar 25, 2011 1:12 pm
Location: Seattle, WA

particle script helper

Postby patrick » Wed Nov 16, 2011 3:05 pm

Grabbing this now to go into the SDK release. Thanks again for contributing it!
User avatar
patrick
 
Posts: 589
Joined: Sat Apr 02, 2011 10:50 pm

particle script helper

Postby tommo.zhou » Thu Nov 17, 2011 12:08 am

Wiki page added.

There's a bug in my script. I've fixed it and uploaded to pastebin, please replace it in the release. 

http://pastebin.com/feWDLXyT

:)



*EDIT:

I think it might be handy if there are some basic math functions in particle script, like cos/sin...
tommo.zhou
 
Posts: 81
Joined: Thu Sep 29, 2011 12:28 am

particle script helper

Postby pygy79 » Fri Jan 06, 2012 9:45 am

This is very cool :-)



I have a suggestion. Rather than using setfenv, you could pass what is currently the environment as an explicit parameter. 

It makes the DSL slightly heavier, but not much, and you don't have to worry about shadowing the magic variables with upvalues, or to declare upvalues to access otherwise global variables inside the callbacks.
local init=makeParticleScript(function(_) _.r1=180-vecAngle(_.p.dx,_.p.dy)   --r1 is a register end,reg) local render=makeParticleScript(function(_) _.p.x=_.p.x+_.p.dx _.p.y=_.p.y+_.p.dy _.sprite() _.sp.rot=_.r1 _.sp.sx=_.ease(0.1,3,MOAIEaseType.SHARP_EASE_IN) _.sp.opacity=_.ease(1,0,MOAIEaseType.EASE_OUT) end,reg)

User avatar
pygy79
 
Posts: 69
Joined: Wed Jan 04, 2012 3:13 am

particle script helper

Postby patrick » Fri Jan 06, 2012 4:23 pm

@tommo.zhou Additional trig functions are in our backlog. The code is in moai-dev under samples/contrib - just send me a pull request if/when you want to update it.
User avatar
patrick
 
Posts: 589
Joined: Sat Apr 02, 2011 10:50 pm


Return to Made With Moai

Who is online

Users browsing this forum: No registered users and 0 guests

x