Cocos2DXNA / cocos2d-xna

XNA Port of Cocos2d-X
www.cocos2dxna.com
227 stars 123 forks source link

Issue 403 - Lightning effect #405

Closed totallyeviljake closed 10 years ago

totallyeviljake commented 10 years ago

This implementation is a single bolt as a CCDrawNode. You can create a series of strikes by adding more bolt instances. See the DrawPrimitivesTest for details:

    public override void TouchEnded(CCTouch touch)
    {
        base.TouchEnded(touch);
        CCLightning node = (CCLightning)GetChildByTag(55);
        node.AddBolt(new CCLightningBolt()
        {
            BoltColor = CCLightning.LightningBlue,
            BoltGlowColor = CCLightning.LightningBlue,
            Start = CCDirector.SharedDirector.WinSize.Center,
            End = ConvertToNodeSpace(touch.Location),
            StrikeTime = (2f * CCMacros.CCRandomBetween0And1()),
            FadeTime = 0.15f,
            Width = .5f
        });
    }

StrikeTime is the amount of time, in seconds, that it takes for the lightning to strike its target. The FadeTime is the amount of time for the strike to fade out.

This PR also include some optimizations to the CCDrawNode to cache a filtered array of primitives so that the hard 65535 primitive limit in XNA doesn't get triggered in CCDrawManager.