public void SetUpSnowField() { emitter = new CAEmitterLayer(); this.BackgroundColor = UIColor.Clear; emitter.Position = new PointF(UIScreen.MainScreen.Bounds.Width /2, -10f); emitter.Size = new SizeF(UIScreen.MainScreen.Bounds.Width,1); emitter.Shape = CAEmitterLayer.ShapeLine; var cell = new CAEmitterCell(); cell.BirthRate = 10f; cell.LifeTime = 9.0f; cell.Contents = UIImage.FromFile("snow-1.png").CGImage; cell.Velocity = 10f; cell.VelocityRange = 50f; cell.EmissionRange = (float) (2f*Math.PI); cell.EmissionLongitude = (float) Math.PI; cell.AccelerationY = 40f; cell.Scale = 1.0f; cell.ScaleRange = 0.2f; cell.SpinRange = 10.0f; emitter.Cells = new CAEmitterCell[] { cell };//, cell2, cell3 }; emitter.RenderMode = CAEmitterLayer.RenderUnordered; Layer.AddSublayer(emitter); }
public void SetUpSnowField() { emitter = new CAEmitterLayer(); this.BackgroundColor = UIColor.Clear; emitter.Position = new PointF(UIScreen.MainScreen.Bounds.Width / 2, -10f); emitter.Size = new SizeF(UIScreen.MainScreen.Bounds.Width, 1); emitter.Shape = CAEmitterLayer.ShapeLine; var cell = new CAEmitterCell(); cell.BirthRate = 10f; cell.LifeTime = 9.0f; cell.Contents = UIImage.FromFile("snow-1.png").CGImage; cell.Velocity = 10f; cell.VelocityRange = 50f; cell.EmissionRange = (float)(2f * Math.PI); cell.EmissionLongitude = (float)Math.PI; cell.AccelerationY = 40f; cell.Scale = 1.0f; cell.ScaleRange = 0.2f; cell.SpinRange = 10.0f; emitter.Cells = new CAEmitterCell[] { cell }; //, cell2, cell3 }; emitter.RenderMode = CAEmitterLayer.RenderUnordered; Layer.AddSublayer(emitter); }
private void Initialize() { // Setup a particle system to folow the user's finger while drawing gestures. this.Position = new PointF(50f, 50f); this.Size = new SizeF(2f, 2f); this.fireCell = CAEmitterCell.EmitterCell(); this.fireCell.BirthRate = 0; this.fireCell.LifeTime = 1.5f; this.fireCell.LifetimeRange = 0.5f; this.fireCell.Color = UIColor.FromRGBA(0.8f, 0.4f, 0.2f, 0.1f).CGColor; this.fireCell.Contents = UIImage.FromBundle("particles_fire.png").CGImage; this.fireCell.Name = "fire"; this.fireCell.Velocity = 3; this.fireCell.VelocityRange = 2; this.fireCell.EmissionRange = (float)Math.PI / 2f; this.fireCell.ScaleSpeed = 0.1f; this.fireCell.Spin = 0.3f; this.RenderMode = CAEmitterLayer.RenderAdditive; //add the cell to the layer and we're done this.Cells = new CAEmitterCell[] { this.fireCell }; }
public override void ViewDidLoad() { base.ViewDidLoad(); var snowEmitter = new CAEmitterLayer(); snowEmitter.Position = new CGPoint(this.View.Bounds.Width / 2.0f + 40f, -10f); snowEmitter.Size = new CGSize(this.View.Bounds.Size.Width * 2.0f, 0.0f); snowEmitter.Mode = "kCAEmitterLayerOutline"; snowEmitter.Shape = "kCAEmitterLayerLine"; var snowFlake = new CAEmitterCell(); snowFlake.BirthRate = 1.0f; snowFlake.LifeTime = 120.0f; snowFlake.Velocity = -10; snowFlake.VelocityRange = 10; snowFlake.AccelerationY = 2; snowFlake.EmissionRange = 0.5f * (nfloat)Math.PI; snowFlake.SpinRange = 0.25f * (nfloat)Math.PI; snowFlake.Contents = UIImage.FromBundle("DazFlake").CGImage; snowFlake.Color = UIColor.FromRGBA(0.600F, 0.658f, 0.743f, 1.0f).CGColor; snowEmitter.ShadowOpacity = 1.0f; snowEmitter.ShadowOffset = new CGSize(0.0f, 1.0f); snowEmitter.ShadowRadius = 0.0f; snowEmitter.ShadowColor = UIColor.Black.CGColor; snowEmitter.Cells = new CAEmitterCell[] { snowFlake }; this.View.Layer.AddSublayer(snowEmitter); }
public ParticleEffect() { tapDetector = new UITapGestureRecognizer(() => { var control = Control ?? Container; var tapPoint = tapDetector.LocationInView(control); var effect = (ParticlesSample.Effects.ParticleEffect)Element.Effects.FirstOrDefault(p => p is ParticlesSample.Effects.ParticleEffect); var mode = effect?.Mode ?? ParticlesSample.Effects.EmitMode.OneShot; var lifeTime = effect?.LifeTime ?? 1.5f; var numberOfItems = effect?.NumberOfParticles ?? 4000; var scale = effect?.Scale ?? 1.0f; var speed = effect?.Speed * 1000 ?? 100.0f; var image = effect?.Image ?? "Icon"; var emitterLayer = new CAEmitterLayer(); emitterLayer.Position = tapPoint; emitterLayer.Shape = CAEmitterLayer.ShapeCircle; var cell = new CAEmitterCell(); cell.Name = "pEmitter"; cell.BirthRate = numberOfItems; cell.Scale = 0f; cell.ScaleRange = scale; cell.Velocity = speed; cell.LifeTime = (float)lifeTime; cell.EmissionRange = (nfloat)Math.PI * 2.0f; cell.Contents = UIImage.FromBundle(image).CGImage; emitterLayer.Cells = new CAEmitterCell[] { cell }; control.Layer.AddSublayer(emitterLayer); if (mode == ParticlesSample.Effects.EmitMode.OneShot) { Task.Delay(1).ContinueWith(t => { Device.BeginInvokeOnMainThread(() => { emitterLayer.SetValueForKeyPath(NSNumber.FromInt32(0), new NSString("emitterCells.pEmitter.birthRate")); }); }); } }); }
public void XEmitterCellTest() { using (var ec = new CAEmitterCell()) { // ICAMediaTiming Assert.That(ec.BeginTime, Is.EqualTo(0.0d), "BeginTime"); Assert.True(Double.IsInfinity(ec.Duration), "Duration"); Assert.That(ec.Speed, Is.EqualTo(1.0f), "Speed"); Assert.That(ec.TimeOffset, Is.EqualTo(0.0d), "TimeOffset"); Assert.That(ec.RepeatCount, Is.EqualTo(0.0f), "RepeatCount"); Assert.That(ec.RepeatDuration, Is.EqualTo(0.0d), "RepeatDuration"); Assert.False(ec.AutoReverses, "AutoReverses"); Assert.That(ec.FillMode, Is.EqualTo("removed"), "FillMode"); } }
/// <summary> /// Initializes a new instance of the <see cref="SuperKoikoukesse.iOS.PXNComboGauge"/> class. /// </summary> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="width">Width.</param> /// <param name="height">Height.</param> public PXNComboGauge(float x, float y, float width, float height) { // Emitter properties Position = new PointF(x, y); ZPosition = 0; Size = new SizeF(width, height); Depth = 0.00f; Shape = CAEmitterLayer.ShapeRectangle; RenderMode = CAEmitterLayer.RenderAdditive; Seed = 1813220680; // Cell properties var cellOne = CreateCellOne(); Cells = new CAEmitterCell[] {cellOne}; }
/// <summary> /// Create a cell. /// </summary> /// <returns>The cell one.</returns> private CAEmitterCell CreateCellOne() { var cell = new CAEmitterCell(); cell.Name = "one"; cell.Enabled = true; cell.Contents = new UIImage("particle.png").CGImage; cell.ContentsRect = new RectangleF(0.00f, 0.00f, 1.00f, 1.00f); cell.MagnificationFilter = CALayer.FilterLinear; cell.MinificationFilter = CALayer.FilterLinear; cell.MinificationFilterBias = 0.00f; cell.Scale = 0; cell.ScaleRange = 0.50f; cell.ScaleSpeed = 0.10f; cell.Color = UIColor.FromRGBA(0.16f, 0.57f, 0.94f, 1f).CGColor; cell.RedRange = 0.70f; cell.GreenRange = 0.00f; cell.BlueRange = 0.00f; cell.AlphaRange = 1.00f; cell.RedSpeed = 0.00f; cell.GreenSpeed = 0.00f; cell.BlueSpeed = 0.00f; cell.AlphaSpeed = -1.00f; cell.LifeTime = 3f; cell.LifetimeRange = 0.80f; cell.BirthRate = 300; cell.Velocity = 0.00f; cell.VelocityRange = 10.00f; cell.AccelerationX = -20.00f; cell.AccelerationY = 0.00f; cell.AccelerationZ = 10.00f; cell.Spin = 0.000f; cell.SpinRange = 0.000f; cell.EmissionLatitude = 0.000f; cell.EmissionLongitude = 0.000f; cell.EmissionRange = 6.283f; return cell; }
private void ShowSnow(int x) { this.Layer = new CAEmitterLayer(); this.Layer.Position = new CGPoint(x, 320); CAEmitterCell cell = new CAEmitterCell(); cell.BirthRate = 100; cell.LifeTime = 10; cell.Velocity = 100; cell.Scale = 0.4f; cell.EmissionRange = 3.14f * 2; cell.Contents = NSImage.ImageNamed("snow.png").CGImage; this.Layer.Cells = new CAEmitterCell[1] { cell }; this.View.Layer.AddSublayer(this.Layer); }
public override void ViewDidLoad() { base.ViewDidLoad(); heartsEmitter.Position = new CGPoint(BtnSpreadLove.Frame.X + BtnSpreadLove.Frame.Size.Width / 2.0f, BtnSpreadLove.Frame.Y + BtnSpreadLove.Frame.Size.Height / 2.0f); heartsEmitter.Size = BtnSpreadLove.Bounds.Size; heartsEmitter.Mode = "kCAEmitterLayerVolume"; heartsEmitter.Shape = "kCAEmitterLayerRectangle"; heartsEmitter.RenderMode = "kCAEmitterLayerAdditive"; CAEmitterCell heart = new CAEmitterCell(); heart.Name = "heart"; heart.EmissionLongitude = (nfloat)Math.PI / 2.0f; heart.EmissionRange = 0.55f * (nfloat)Math.PI; heart.BirthRate = 0.0f; heart.LifeTime = 10.0f; heart.Velocity = -120; heart.VelocityRange = 60; heart.AccelerationY = 20; heart.Contents = UIImage.FromBundle("DazHeart").CGImage; heart.Color = UIColor.FromRGBA(0.5f, 0.0f, 0.5f, 0.5f).CGColor; heart.RedRange = 0.3f; heart.BlueRange = 0.3f; heart.AlphaSpeed = -0.5f / heart.LifeTime; heart.Scale = 0.15f; heart.ScaleSpeed = 0.5f; heart.SpinRange = 2.0f * (nfloat)Math.PI; heartsEmitter.Cells = new CAEmitterCell[] { heart }; this.View.Layer.AddSublayer(heartsEmitter); BtnSpreadLove.TouchUpInside += (sender, e) => { var heartsBurst = CABasicAnimation.FromKeyPath("emitterCells.heart.birthRate"); heartsBurst.From = NSNumber.FromFloat(10.0f); heartsBurst.To = NSNumber.FromFloat(0.0f); heartsBurst.Duration = 15.0f; heartsBurst.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear); heartsEmitter.AddAnimation(heartsBurst, "heartsBurst"); }; }
public void Start() { string fileName = NSBundle.MainBundle.PathForResource ("tspark", "png"); var dataProvider = CGDataProvider.FromFile (fileName); var img = CGImage.FromPNG (dataProvider, null, false, CGColorRenderingIntent.Default); mortor = new CAEmitterLayer { Position =new PointF (Bounds.Width / 2, 0), RenderMode = CAEmitterLayer.RenderAdditive, }; var pi = (float)Math.PI; var rocket =new CAEmitterCell(); rocket.EmissionLongitude = pi / 3; rocket.EmissionLatitude = 0; rocket.LifeTime = 1.6f; rocket.BirthRate = 1.5f; rocket.Velocity = 40; rocket.VelocityRange = 600; rocket.AccelerationY = -250; rocket.EmissionRange = pi / 4; var color = UIColor.FromRGBA (.5f, .5f, .5f, .5f).CGColor; rocket.Color = color; rocket.RedRange = 0.5f; rocket.GreenRange = 0.5f; rocket.BlueRange = 0.5f; rocket.Name = "rocket"; CAEmitterCell flare = CAEmitterCell.EmitterCell(); flare.Contents = img; flare.EmissionLongitude = (4 * pi) / 2; flare.Scale = 0.4f; flare.Velocity = 100; flare.BirthRate = 45; flare.LifeTime = 1.5f; flare.AccelerationY = -350; flare.EmissionRange = pi / 7; flare.AlphaSpeed = -0.7f; flare.ScaleSpeed = -0.1f; flare.ScaleRange = 0.1f; flare.BeginTime = 0.01; flare.Duration = 0.7; CAEmitterCell firework = CAEmitterCell.EmitterCell(); firework.Contents = img; firework.BirthRate = 9999; firework.Scale = 0.6f; firework.Velocity = 130; firework.LifeTime = 2; firework.AlphaSpeed = -0.2f; firework.AccelerationY = -80; firework.BeginTime = 1.5; firework.Duration = 0.1; firework.EmissionRange = 2 * pi; firework.ScaleSpeed = -0.1f; firework.Spin = 2; firework.Name = ("firework"); CAEmitterCell preSpark = CAEmitterCell.EmitterCell(); preSpark.BirthRate = 80; preSpark.Velocity = firework.Velocity * 0.7f; preSpark.LifeTime = 1.7f; preSpark.AccelerationY = firework.AccelerationY * 0.85f; preSpark.BeginTime = firework.BeginTime - 0.2; preSpark.EmissionRange = firework.EmissionRange; preSpark.GreenSpeed = 100; preSpark.BlueSpeed = 100; preSpark.RedSpeed = 100; preSpark.Name = ("preSpark"); CAEmitterCell spark = CAEmitterCell.EmitterCell(); spark.Contents = img; spark.LifeTime = 0.05f; spark.AccelerationY = -250; spark.BeginTime = 0.8; spark.Scale = 0.4f; spark.BirthRate = 10; preSpark.Cells = new []{spark}; rocket.Cells = new []{flare, firework, preSpark}; mortor.Cells = new []{rocket}; this.Layer.AddSublayer(mortor); SetNeedsLayout (); this.Layer.SetNeedsDisplay (); }
private void ShowFire() { CGRect viewBounds = this.View.Layer.Bounds; this.Layer = new CAEmitterLayer(); //this.Layer.Position= new CGPoint(0, 320); //this.Layer.Position = new CGPoint(viewBounds.Size.Width / 2.0, viewBounds.Size.Height / 2.0); this.Layer.Position = new CGPoint(0, viewBounds.Size.Height / 2.0); this.Layer.Size = new CGSize(viewBounds.Size.Width / 2.0, 0.0); this.Layer.Mode = "kCAEmitterLayerOutline"; this.Layer.Shape = "kCAEmitterLayerLine"; this.Layer.RenderMode = "kCAEmitterLayerAdditive"; Random rad = new Random(); int radnum = rad.Next(0, 100); this.Layer.Seed = radnum + 1; //1.rocket CAEmitterCell rocket = new CAEmitterCell(); rocket.BirthRate = 1.0f; rocket.EmissionRange = 0.25f * 3.14f; // some variation in angle rocket.Velocity = 380; rocket.VelocityRange = 100; rocket.AccelerationY = 75; rocket.LifeTime = 1.02f; // we cannot set the birthrate < 1.0 for the burst rocket.Contents = NSImage.ImageNamed("snow.png").CGImage; rocket.Scale = 0.2f; rocket.Color = new CGColor(1, 0, 0); rocket.GreenRange = 1.0f; // different colors rocket.RedRange = 1.0f; rocket.BlueRange = 1.0f; rocket.SpinRange = 3.14f; //2.burst CAEmitterCell burst = new CAEmitterCell(); burst.BirthRate = 1.0f; // at the end of travel burst.Velocity = 0; burst.Scale = 2.5f; burst.RedSpeed = -1.5f; // shifting burst.BlueSpeed = +1.5f; // shifting burst.GreenSpeed = +1.0f; // shifting burst.LifeTime = 0.35f; //3.spark CAEmitterCell spark = new CAEmitterCell(); spark.BirthRate = 400f; spark.Velocity = 125f; spark.EmissionRange = 2f * 3.14f; // 360 deg spark.AccelerationY = 75f; // gravity spark.LifeTime = 3f; spark.Contents = NSImage.ImageNamed("snow.png").CGImage; spark.ScaleSpeed = -0.2f; spark.GreenSpeed = -0.1f; spark.RedSpeed = 0.4f; spark.BlueSpeed = -0.1f; spark.AlphaSpeed = -0.25f; spark.Spin = 1f * 3.14f; spark.SpinRange = 2f * 3.14f; this.Layer.Cells = new CAEmitterCell[1] { rocket }; rocket.Cells = new CAEmitterCell[1] { burst }; burst.Cells = new CAEmitterCell[1] { spark }; this.View.Layer.AddSublayer(this.Layer); //remar3333 }
public override void AwakeFromNib() { // Create the root layer rootLayer = new CALayer(); // Set the root layer;s background color to black rootLayer.BackgroundColor = new CGColor(0, 0, 0); // Create the fire emitter layer fireEmitter = new CAEmitterLayer(); fireEmitter.Position = new System.Drawing.PointF(225, 50); fireEmitter.Mode = CAEmitterLayer.ModeOutline; fireEmitter.Shape = CAEmitterLayer.ShapeLine; fireEmitter.RenderMode = CAEmitterLayer.RenderAdditive; fireEmitter.Size = new SizeF(0, 0); // Create the smoke emitter layer smokeEmitter = new CAEmitterLayer(); smokeEmitter.Position = new PointF(225, 50); smokeEmitter.Mode = CAEmitterLayer.ModePoints; // Create the fire emitter cell CAEmitterCell fire = CAEmitterCell.EmitterCell(); fire.EmissionLongitude = (float)Math.PI; fire.BirthRate = 0; fire.Velocity = 80; fire.VelocityRange = 30; fire.EmissionRange = 1.1f; fire.AccelerationY = 200; fire.ScaleSpeed = 0.3f; RectangleF rect = RectangleF.Empty; CGColor color = new CGColor(0.8f, 0.4f, 0.2f, 0.10f); fire.Color = color; fire.Contents = NSImage.ImageNamed("fire.png").AsCGImage(ref rect, null, null); // Name the cell so that it can be animated later using keypaths fire.Name = "fire"; // Add the fire emitter cell to the fire emitter layer fireEmitter.Cells = new CAEmitterCell[] { fire }; //Create the smoke emitter cell CAEmitterCell smoke = CAEmitterCell.EmitterCell(); smoke.BirthRate = 11; smoke.EmissionLongitude = (float)Math.PI / 2; smoke.LifeTime = 0; smoke.Velocity = 40; smoke.VelocityRange = 20; smoke.EmissionRange = (float)Math.PI / 4; smoke.Spin = 1; smoke.SpinRange = 6; smoke.AccelerationY = 160; smoke.Scale = 0.1f; smoke.AlphaSpeed = -0.12f; smoke.ScaleSpeed = 0.7f; smoke.Contents = NSImage.ImageNamed("smoke.png").AsCGImage(ref rect, null, null); //Name the cell so that it can be animated later using keypaths smoke.Name = "smoke"; // Add the smoke emitter cell to the smoke emitter layer smokeEmitter.Cells = new CAEmitterCell[] { smoke }; // Add the two emitter layers to the root layer rootLayer.AddSublayer(smokeEmitter); rootLayer.AddSublayer(fireEmitter); // Set the view's layer to the base layer view.Layer = rootLayer; view.WantsLayer = true; // Set the fire simulation to reflect the intial slider postion slidersChanged(this); // Force the view to update view.NeedsDisplay = true; }