private SCNAction FlashAnimation(double duration) { var action = SCNAction.CustomAction(duration, (node, elapsedTime) => { // animate color from HSB 48/100/100 to 48/30/100 and back var elapsedTimePercentage = elapsedTime / (float)duration; var saturation = 2.8f * (elapsedTimePercentage - 0.5f) * (elapsedTimePercentage - 0.5f) + 0.3f; var material = node.Geometry.FirstMaterial; if (material != null) { material.Diffuse.Contents = UIColor.FromHSBA(0.1333f, saturation, 1.0f, 1.0f); } }); return(action); }
public void CollectBanana(SCNNode banana) { // Flyoff the banana to the screen space position score label. // Don't increment score until the banana hits the score label. // ignore collisions banana.PhysicsBody = null; BananasCollected++; int variance = 60; nfloat duration = 0.25f; nfloat apexY = worldSpaceLabelScorePosition.Y * 0.8f + (new Random().Next(0, variance) - variance / 2); worldSpaceLabelScorePosition.Z = banana.Position.Z; var apex = new SCNVector3(banana.Position.X + 10 + (new Random().Next(0, variance) - variance / 2), apexY, banana.Position.Z); SCNAction startFlyOff = SCNAction.MoveTo(apex, duration); startFlyOff.TimingMode = SCNActionTimingMode.EaseOut; SCNAction endFlyOff = SCNAction.CustomAction(duration, new SCNActionNodeWithElapsedTimeHandler((node, elapsedTime) => { nfloat t = elapsedTime / duration; var v = new SCNVector3( apex.X + ((worldSpaceLabelScorePosition.X - apex.X) * t), apex.Y + ((worldSpaceLabelScorePosition.Y - apex.Y) * t), apex.X + ((worldSpaceLabelScorePosition.Z - apex.Z) * t)); node.Position = v; })); endFlyOff.TimingMode = SCNActionTimingMode.EaseInEaseOut; SCNAction flyoffSequence = SCNAction.Sequence(new SCNAction[] { startFlyOff, endFlyOff }); banana.RunAction(flyoffSequence, () => { Bananas.Remove(banana); banana.RemoveFromParentNode(); // Add to score. Score++; GameSimulation.Sim.PlaySound("deposit.caf"); // Game Over if (Bananas.Count == 0) { DoGameOver(); } }); }