Пример #1
0
    public static Scene MakeParticlesScene()
    {
        var scene = new Scene()
        {
            Name = "Particles"
        };

        float scale = 1.5f;

        var body = new SpriteUV(new TextureInfo(new Texture2D("/Application/Sample/GameEngine2D/FeatureCatalog/data/arrow.png", false), new Vector2i(4, 4)));

        body.CenterSprite(TRS.Local.BottomCenter);
        body.Scale     = body.TextureInfo.TextureSizef * scene.Camera.GetPixelSize() * scale;
        body.BlendMode = BlendMode.Additive;

        scene.AddChild(body);

        body.Schedule((dt) => {
            if (Input2.Touch00.Down)
            {
                Vector2 touch_pos = Director.Instance.CurrentScene.Camera.GetTouchPos();
                if ((body.Position - touch_pos).Length() > 0.01f)
                {
                    body.Rotation = Math.LerpUnitVectors(body.Rotation, Math.Perp((body.Position - touch_pos).Normalize( )), 0.3f);
                }
                body.Position = Math.Lerp(body.Position, touch_pos, 0.3f);
            }

            body.Position += Input2.GamePad0.Dpad * 0.1f;
        });

        Particles      fire_node = new Particles(300);
        ParticleSystem fire      = fire_node.ParticleSystem;

        fire.TextureInfo = new TextureInfo(new Texture2D("/Application/Sample/GameEngine2D/FeatureCatalog/data/fire.png", false));
//		fire.BlendMode = BlendMode.PremultipliedAlpha;

        fire_node.Schedule((dt) =>

        {
            fire.Emit.Transform = fire_node.GetWorldTransform();
            fire.Emit.TransformForVelocityEstimate = fire_node.GetWorldTransform();
            fire.RenderTransform = Director.Instance.CurrentScene.GetWorldTransform();                     // most probably identity
        }

                           , -1);

        fire_node.AdHocDraw += () =>

        {
            // debug draw the emission rectangle in pink

            Director.Instance.GL.SetBlendMode(BlendMode.Additive);
            Director.Instance.DrawHelpers.SetColor(Colors.Pink * 0.3f);
            Director.Instance.DrawHelpers.DrawBounds2(Bounds2.QuadMinus1_1.Scale(fire.Emit.PositionVar, Math._00));
        };

        fire.Emit.Velocity        = new Vector2(0.0f, -2.0f);
        fire.Emit.VelocityVar     = new Vector2(0.2f, 0.3f);
        fire.Emit.ForwardMomentum = 0.2f;
        fire.Emit.AngularMomentun = 0.0f;
        fire.Emit.LifeSpan        = 0.4f;
        fire.Emit.WaitTime        = 0.005f;
        float s = 0.25f;

        fire_node.Position         = new Vector2(0.0f, -s);
        fire.Emit.PositionVar      = new Vector2(s, s);
        fire.Emit.ColorStart       = Colors.Red;
        fire.Emit.ColorStartVar    = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
        fire.Emit.ColorEnd         = Colors.White;
        fire.Emit.ColorEndVar      = new Vector4(0.2f, 0.0f, 0.0f, 0.0f);
        fire.Emit.ScaleStart       = 0.3f * scale;
        fire.Emit.ScaleStartRelVar = 0.2f;
        fire.Emit.ScaleEnd         = 0.6f * scale;
        fire.Emit.ScaleEndRelVar   = 0.2f;
        fire.Simulation.Fade       = 0.3f;

        body.AddChild(fire_node);

        Particles      smoke_node = new Particles(300);
        ParticleSystem smoke      = smoke_node.ParticleSystem;

        smoke.TextureInfo = new TextureInfo(new Texture2D("/Application/Sample/GameEngine2D/FeatureCatalog/data/fire.png", false));
//		smoke.BlendMode = BlendMode.PremultipliedAlpha;

        smoke_node.Schedule((dt) =>

        {
            smoke.Emit.Transform = smoke_node.GetWorldTransform();
            smoke.Emit.TransformForVelocityEstimate = smoke_node.GetWorldTransform();
            smoke.RenderTransform = Director.Instance.CurrentScene.GetWorldTransform();                     // most probably identity
        }

                            , -1);

        smoke_node.AdHocDraw += () =>

        {
            // debug draw the emission rectangle in pink

            Director.Instance.GL.SetBlendMode(BlendMode.Additive);
            Director.Instance.DrawHelpers.SetColor(Colors.Pink * 0.3f);
            Director.Instance.DrawHelpers.DrawBounds2(Bounds2.QuadMinus1_1.Scale(smoke.Emit.PositionVar, Math._00));
        };

        smoke.Emit.Velocity        = new Vector2(0.0f, -2.0f);
        smoke.Emit.VelocityVar     = new Vector2(0.2f, 0.3f);
        smoke.Emit.ForwardMomentum = 0.2f;
        smoke.Emit.AngularMomentun = 0.0f;
        smoke.Emit.LifeSpan        = 2.4f;
        smoke.Emit.WaitTime        = 0.02f;

        smoke_node.Position         = new Vector2(0.0f, -s);
        smoke.Emit.PositionVar      = new Vector2(s, s);
        smoke.Emit.ColorStart       = Colors.Black;
        smoke.Emit.ColorStartVar    = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
        smoke.Emit.ColorEnd         = Colors.Grey30;
        smoke.Emit.ColorEndVar      = new Vector4(0.2f, 0.0f, 0.0f, 0.0f);
        smoke.Emit.ScaleStart       = 0.3f * scale * 3.0f;
        smoke.Emit.ScaleStartRelVar = 0.2f;
        smoke.Emit.ScaleEnd         = 0.6f * scale * 4.0f;
        smoke.Emit.ScaleEndRelVar   = 0.2f;
        smoke.Simulation.Fade       = 0.3f;

        body.AddChild(smoke_node);

        scene.RegisterDisposeOnExit((System.IDisposable)fire);
        scene.RegisterDisposeOnExit((System.IDisposable)smoke);
        scene.RegisterDisposeOnExit((System.IDisposable)body.TextureInfo);

        return(scene);
    }