I've implemented the lightning effect in Corona SDK using Lua and the algorithm as described in the following article.
http://drilian.com/2009/02/25/lightning-bolts/
The result can be seen here:
http://www.youtube.com/watch?v=JnRxfs87ppk
The vector class I used in this file was extended from the following gist:
https://gist.github.com/1006414
Write something like this to create a new lightning. You need to pass the starting and target positions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | local util = require("util") _W = display.contentWidth _H = display.contentHeight gameStates = { menu = 0, pause = 1, gameOver = 2, levelSelection = 3, lightning = 4, inGame = 5}; currentState = gameStates["menu"]; function onTouch(event) if (event.phase == "began") then print("creating lightning...") util.newLightning(_W/2,_H/2,event.x,event.y) _G.currentState = gameStates["lightning"] end end Runtime:addEventListener("touch", onTouch) |
Thanks,
Aung Sithu
http://rivaledge.sg
Cool. :D
Cheers!
I'm confused how the lightningupdate event knows what startPointX,startPointY, targetX, targetY are as these are not stored.
and each invocation of newLightning will have different values - so it works, but should it?
:-?
I really like! Thanks!
nice :) would be good to have a bitmap library in corona to be able to do plasma effects.
my build on your ontouch :)