public override void DidSimulatePhysics()
        {
            base.DidSimulatePhysics();

            // Get the position either of the default hero or the hero spawn point.
            HeroCharacter defaultHero = DefaultPlayer.Hero;
            CGPoint       position;

            if (defaultHero != null && Heroes.Contains(defaultHero))
            {
                position = defaultHero.Position;
            }
            else
            {
                position = DefaultSpawnCGPoint;
            }

            // Update the alphas of any trees that are near the hero (center of the camera) and therefore visible or soon to be visible.
            foreach (Tree tree in trees)
            {
                if (GraphicsUtilities.DistanceBetweenCGPoints(tree.Position, position) < 1024)
                {
                    tree.UpdateAlphaWithScene(this);
                }
            }

            if (!WorldMovedForUpdate)
            {
                return;
            }

            // Show any nearby hidden particle systems and hide those that are too far away to be seen.
            foreach (SKEmitterNode particles in particleSystems)
            {
                bool particlesAreVisible = GraphicsUtilities.DistanceBetweenCGPoints(particles.Position, position) < 1024;

                if (!particlesAreVisible && !particles.Paused)
                {
                    particles.Paused = true;
                }
                else if (particlesAreVisible && particles.Paused)
                {
                    particles.Paused = false;
                }
            }

            // Update nearby parallax sprites.
            foreach (ParallaxSprite sprite in parallaxSprites)
            {
                if (GraphicsUtilities.DistanceBetweenCGPoints(sprite.Position, position) >= 1024)
                {
                    continue;
                }

                sprite.UpdateOffset();
            }
        }
Example #2
0
 public bool ContainsHero(Hero hero)
 {
     return(Heroes.Contains(hero));
 }