public DoubleAnimationSample(Microsoft.Xna.Framework.Game game) : base(game) { Rectangle bounds = GraphicsService.GraphicsDevice.Viewport.TitleSafeArea; // A 2 second from/to animation. DoubleFromToByAnimation doubleAnimation = new DoubleFromToByAnimation { From = bounds.Left + 200, To = bounds.Right - 200, Duration = TimeSpan.FromSeconds(2), EasingFunction = new QuadraticEase { Mode = EasingMode.EaseInOut }, }; // Make the from/to animation oscillate forever. AnimationClip <double> oscillatingDoubleAnimation = new AnimationClip <double>(doubleAnimation) { LoopBehavior = LoopBehavior.Oscillate, Duration = TimeSpan.MaxValue, }; AnimationService.StartAnimation(oscillatingDoubleAnimation, _animatableDouble).UpdateAndApply(); }
public void Setup(float[] fillData) { animationService = GlobalState.AnimationService; scanMap.Load(); var level = gameObject.GetComponentInParent <Level>(); var anchorLength = anchors.Length; var anchorIndex = 0; for (int index = 0, length = fillData.Length; index < length; index++) { if (anchorIndex < anchorLength) { if (fillData[index] > 0.0f) { var powerUp = powerUpFactory.CreateByType((PowerUpType)(1 << index)); var powerUpComponent = powerUp.GetComponent <PowerUp>(); powerUpComponent.Setup(fillData[index], this, level, fillCharacter); powerUp.transform.SetParent(anchors[anchorIndex]); powerUp.transform.localPosition = Vector3.zero; anchorIndex++; powerUps.Add(powerUpComponent); } } else { break; } } }
public StringAnimationSample(Microsoft.Xna.Framework.Game game) : base(game) { // A key-frame animation of string values. // Note: The key frame animation plays all strings and then holds the last key frame // because the default KeyFrameAnimation.FillBehavior is "Hold". StringKeyFrameAnimation keyFrameAnimation = new StringKeyFrameAnimation(); keyFrameAnimation.KeyFrames.Add(new KeyFrame <string>(TimeSpan.FromSeconds(0), "The")); keyFrameAnimation.KeyFrames.Add(new KeyFrame <string>(TimeSpan.FromSeconds(1), "quick")); keyFrameAnimation.KeyFrames.Add(new KeyFrame <string>(TimeSpan.FromSeconds(2), "brown")); keyFrameAnimation.KeyFrames.Add(new KeyFrame <string>(TimeSpan.FromSeconds(3), "fox")); keyFrameAnimation.KeyFrames.Add(new KeyFrame <string>(TimeSpan.FromSeconds(4), "jumps")); keyFrameAnimation.KeyFrames.Add(new KeyFrame <string>(TimeSpan.FromSeconds(5), "over")); keyFrameAnimation.KeyFrames.Add(new KeyFrame <string>(TimeSpan.FromSeconds(6), "the")); keyFrameAnimation.KeyFrames.Add(new KeyFrame <string>(TimeSpan.FromSeconds(7), "lazy")); keyFrameAnimation.KeyFrames.Add(new KeyFrame <string>(TimeSpan.FromSeconds(8), "dog.")); // Use an AnimationClip to loop the first 9 seconds of the key-frame animation // forever. The animation speed is set to 2 to make the animation play faster. AnimationClip <string> timelineClip = new AnimationClip <string>(keyFrameAnimation) { LoopBehavior = LoopBehavior.Cycle, ClipStart = TimeSpan.FromSeconds(0), ClipEnd = TimeSpan.FromSeconds(9), Duration = TimeSpan.MaxValue, Speed = 2, }; // Start the animation. AnimationService.StartAnimation(timelineClip, _animatableString); }
private static void CreateCapturedShip(AnimationService animationService, Ship ship, Bug bug) { List <BezierCurve> paths = new List <BezierCurve>(); paths.Add(new BezierCurve() { StartPoint = ship.Location, EndPoint = new PointF(bug.Location.X, bug.Location.Y + 50), ControlPoint1 = ship.Location, ControlPoint2 = bug.Location, }); CapturedShip = new Ship() { Sprite = new Sprite(Sprite.SpriteTypes.CapturedShip), Paths = paths, RotateAlongPath = true, Started = true, Index = -999, Speed = 2 }; CapturedShip.Paths.ForEach(a => { CapturedShip.PathPoints.AddRange(animationService.ComputePathPoints(a, true)); }); animationService.Animatables.Add(CapturedShip); }
public BoneJiggleSample(Microsoft.Xna.Framework.Game game) : base(game) { var modelNode = ContentManager.Load <ModelNode>("Dude/Dude"); _meshNode = modelNode.GetSubtree().OfType <MeshNode>().First().Clone(); _meshNode.PoseLocal = new Pose(new Vector3F(0, 0, 0), Matrix33F.CreateRotationY(ConstantsF.Pi)); SampleHelper.EnablePerPixelLighting(_meshNode); GraphicsScreen.Scene.Children.Add(_meshNode); var animations = _meshNode.Mesh.Animations; var walkAnimation = new AnimationClip <SkeletonPose>(animations.Values.First()) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; _walkAnimationController = AnimationService.StartAnimation(walkAnimation, (IAnimatableProperty)_meshNode.SkeletonPose); _walkAnimationController.AutoRecycle(); // Create a BoneJiggler instance for the head bone (bone index 7). _boneJiggler = new BoneJiggler(_meshNode.SkeletonPose, 7, new Vector3F(1.1f, 0, 0)) { Spring = 100, Damping = 3, }; }
public static void InitIntro(AnimationService animationService, int introspeedincrease) { //two groups of four from top for (int i = 0; i < 4; i++) { animationService.Animatables.Add(BugFactory.CreateAnimatable_BugIntro(i, i * Constants.BugIntroSpacing, new Challenge1(), Sprite.SpriteTypes.BlueBug, 1, introspeedincrease, false)); } for (int i = 0; i < 4; i++) { animationService.Animatables.Add(BugFactory.CreateAnimatable_BugIntro(i + 4, i * Constants.BugIntroSpacing, new Challenge2(), Sprite.SpriteTypes.BlueBug, 1, introspeedincrease, false)); } //two groups of eight from bottom for (int i = 0; i < 8; i++) { animationService.Animatables.Add(BugFactory.CreateAnimatable_BugIntro(i + 8, i * Constants.BugIntroSpacing, new Challenge3(), i % 2 != 0 ? Sprite.SpriteTypes.GreenBug : Sprite.SpriteTypes.BlueBug, 2, introspeedincrease, false)); } for (int i = 0; i < 8; i++) { animationService.Animatables.Add(BugFactory.CreateAnimatable_BugIntro(i + 16, i * Constants.BugIntroSpacing, new Challenge4(), Sprite.SpriteTypes.BlueBug, 3, introspeedincrease, false)); } //two groups of eight from top for (int i = 0; i < 8; i++) { animationService.Animatables.Add(BugFactory.CreateAnimatable_BugIntro(i + 24, i * Constants.BugIntroSpacing, new Challenge5(), Sprite.SpriteTypes.BlueBug, 4, introspeedincrease, false)); } for (int i = 0; i < 8; i++) { animationService.Animatables.Add(BugFactory.CreateAnimatable_BugIntro(i + 32, i * Constants.BugIntroSpacing, new Challenge6(), Sprite.SpriteTypes.BlueBug, 5, introspeedincrease, false)); } }
public ManualMeshRenderSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, delegateGraphicsScreen); // Add a custom game object which controls the camera. _cameraObject = new CameraObject(Services); GameObjectService.Objects.Add(_cameraObject); _scene = new Scene(); SceneSample.InitializeDefaultXnaLights(_scene); // For advanced users: Set this flag if you want to analyze the imported opaque data of // effect bindings. EffectBinding.KeepOpaqueData = true; _model = ContentManager.Load <ModelNode>("Dude/Dude").Clone(); var meshNode = _model.GetSubtree().OfType <MeshNode>().First(); meshNode.ScaleLocal = new Vector3(1, 2, 1); var mesh = meshNode.Mesh; var timeline = new TimelineClip(mesh.Animations.Values.First()) { Duration = TimeSpan.MaxValue, LoopBehavior = LoopBehavior.Cycle, }; AnimationService.StartAnimation(timeline, (IAnimatableProperty)meshNode.SkeletonPose); }
public static void ResetAnimation(AnimationService animationService) { foreach (var animatable in animationService.Animatables.Where(a => a.Sprite.SpriteType != Sprite.SpriteTypes.Ship)) { animatable.CurPathPointIndex = animatable.StartDelay; } }
public AttachmentSample(Microsoft.Xna.Framework.Game game) : base(game) { var modelNode = ContentManager.Load <ModelNode>("Marine/PlayerMarine"); _meshNode = modelNode.GetSubtree().OfType <MeshNode>().First().Clone(); SampleHelper.EnablePerPixelLighting(_meshNode); GraphicsScreen.Scene.Children.Add(_meshNode); // Play a looping 'Idle' animation. var animations = _meshNode.Mesh.Animations; var idleAnimation = animations["Idle"]; var loopingAnimation = new AnimationClip <SkeletonPose>(idleAnimation) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; var animationController = AnimationService.StartAnimation(loopingAnimation, (IAnimatableProperty)_meshNode.SkeletonPose); animationController.UpdateAndApply(); animationController.AutoRecycle(); // Add weapon model to the scene graph under the node of the marine mesh. _weaponModelNode = ContentManager.Load <ModelNode>("Marine/Weapon/WeaponMachineGun").Clone(); _meshNode.Children = new SceneNodeCollection(); _meshNode.Children.Add(_weaponModelNode); }
private void RestartAnimations() { // Start original animation on one model. var loopingAnimation = new AnimationClip <SkeletonPose>(_animation) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; AnimationService.StartAnimation(loopingAnimation, (IAnimatableProperty)_meshNodeUncompressed.SkeletonPose); // Clone the original animation. var animationCompressed = _animation.Clone(); // Compress animation. This removes key frames that can be computed from neighboring frames. // This animation is lossy and the parameters define the allowed error. _removedKeyFrames = animationCompressed.Compress(0.01f, _rotationCompressionThreshold, 0.001f); // Finalize the SkeletonKeyFrameAnimation. // (This must be called to optimize the internal data structures.) animationCompressed.Freeze(); // Start compressed animation on the other model. var loopingAnimationCompressed = new AnimationClip <SkeletonPose>(animationCompressed) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; AnimationService.StartAnimation(loopingAnimationCompressed, (IAnimatableProperty)_meshNodeCompressed.SkeletonPose); }
private void CreateAnimationService() { var marker = GameObject.GetComponent <NpcMarker>(); var service = new AnimationService(marker.skeletonAnimation, marker); Services.Add(service); }
private static void CreateTractorBeam(AnimationService animationService, Ship ship, Bug bug) { var tb = new TractorBeam() { DrawPath = false, RotateAlongPath = false, Started = true, DestroyAfterComplete = false, IsMoving = false, PathIsLine = true, Location = new PointF(bug.Location.X, bug.Location.Y + 155) }; tb.SpriteBankIndex = 0; tb.SpriteBank.Add(new Sprite(Sprite.SpriteTypes.TractorBeam)); tb.SpriteBank.Add(new Sprite(Sprite.SpriteTypes.TractorBeam2)); tb.SpriteBank.Add(new Sprite(Sprite.SpriteTypes.TractorBeam3)); tb.SpriteBank.ForEach(a => { a.SourceRect = new Rectangle(0, 0, Constants.BiggerSpriteDestSize.Width, 0); a.DestRect = new Rectangle(0, 0, Constants.BiggerSpriteDestSize.Width, 0); }); animationService.Animatables.Add(tb); }
public static void InitIntro(AnimationService animationService, int introspeedincrease) { //two groups of four from top for (int i = 0; i < 5; i++) { animationService.Animatables.Add(BugFactory.CreateAnimatable_BugIntro(i, i * Constants.BugIntroSpacing, new Intro1(), Sprite.SpriteTypes.BlueBug, 1, introspeedincrease, Utils.Rnd(1, 10) % 2 == 0, i == 4)); } for (int i = 0; i < 5; i++) { animationService.Animatables.Add(BugFactory.CreateAnimatable_BugIntro(i + 4, i * Constants.BugIntroSpacing, new Intro2(), Sprite.SpriteTypes.RedBug, 1, introspeedincrease, Utils.Rnd(1, 10) % 2 == 0, i == 4)); } //two groups of eight from bottom for (int i = 0; i < 8; i++) { animationService.Animatables.Add(BugFactory.CreateAnimatable_BugIntro(i + 8, i * Constants.BugIntroSpacing, new Intro3(), i % 2 != 0 ? Sprite.SpriteTypes.GreenBug : Sprite.SpriteTypes.RedBug, 2, introspeedincrease, Utils.Rnd(1, 10) % 2 == 0)); } for (int i = 0; i < 8; i++) { animationService.Animatables.Add(BugFactory.CreateAnimatable_BugIntro(i + 16, i * Constants.BugIntroSpacing, new Intro4(), Sprite.SpriteTypes.RedBug, 3, introspeedincrease, Utils.Rnd(1, 10) % 2 == 0)); } //two groups of eight from top for (int i = 0; i < 9; i++) { animationService.Animatables.Add(BugFactory.CreateAnimatable_BugIntro(i + 24, i * Constants.BugIntroSpacing, new Intro1(), Sprite.SpriteTypes.BlueBug, 4, introspeedincrease, Utils.Rnd(1, 10) % 2 == 0, i == 8)); } for (int i = 0; i < 9; i++) { animationService.Animatables.Add(BugFactory.CreateAnimatable_BugIntro(i + 32, i * Constants.BugIntroSpacing, new Intro2(), Sprite.SpriteTypes.BlueBug, 5, introspeedincrease, Utils.Rnd(1, 10) % 2 == 0, i == 8)); } }
public static void Fire(Ship ship, AnimationService animationService) { var c = ship.Sprite.SpriteType == Sprite.SpriteTypes.DoubleShip ? 1: 0; for (var i = 0; i <= c; i++) { List <BezierCurve> paths = new List <BezierCurve>(); paths.Add(new BezierCurve() { StartPoint = new PointF(ship.Location.X + ((ship.Sprite.SpriteDestRect.Width / 2) - 14) + (i * 45), Constants.CanvasSize.Height - (Constants.SpriteDestSize.Height * 2) - 5), EndPoint = new PointF(ship.Location.X + ((ship.Sprite.SpriteDestRect.Width / 2) - 16) + (i * 45), -14) }); var missle = new ShipMissle() { Paths = paths, DrawPath = false, PathIsLine = true, RotateAlongPath = false, Started = true, Speed = Constants.ShipMissleSpeed, DestroyAfterComplete = true, }; missle.Paths.ForEach(p => { missle.PathPoints.AddRange(animationService.ComputePathPoints(p, true)); }); animationService.Animatables.Add(missle); } }
public override void Update(GameTime gameTime) { base.Update(gameTime); // <Space> --> Cross-fade to next animation. if (InputService.IsPressed(Keys.Space, true)) { _currentAnimationIndex++; if (_currentAnimationIndex >= _animations.Length) { _currentAnimationIndex = 0; } for (int i = 0; i < NumberOfModels; i++) { // Start a next animation using a Replace transition with a fade-in time. AnimationService.StartAnimation( _animations[_currentAnimationIndex], (IAnimatableProperty <SkeletonPose>)_meshNodes[i].SkeletonPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.2))) .AutoRecycle(); } } // Sidenote: // SkeletonPose.Update() is a method that can be called to update all internal skeleton pose // data immediately. If SkeletonPose.Update() is not called, the internal data will // be updated when needed - for example, when SkeletonPose.SkinningMatricesXna are accessed. //for (int i = 0; i < NumberOfModels; i++) // _meshNodes[i].SkeletonPose.Update(); }
public CustomAnimationSample(Microsoft.Xna.Framework.Game game) : base(game) { // Start the custom circle animation. AnimationService.StartAnimation(new MyCircleAnimation(), _animatablePosition) .UpdateAndApply(); }
protected override void ResolveDependencies() { base.ResolveDependencies(); this.firstUpdate = true; this.animationService = WaveServices.GetService <AnimationService>(); this.audioService = WaveServices.GetService <AudioService>(); var gui = this.EntityManager.Find <Entity>("GUI"); this.scoreControl = gui.FindChild("currentscore").FindComponent <TextComponent>(); var gameController = this.EntityManager.Find("GameController"); this.terrainGeneratorBehavior = gameController.FindComponent <TerrainGeneratorBehavior>(); this.leftOrientation = Quaternion.CreateFromYawPitchRoll(MathHelper.PiOver2, 0f, 0f); this.rightOrientation = Quaternion.CreateFromYawPitchRoll(-MathHelper.PiOver2, 0f, 0f); this.upOrientation = Quaternion.CreateFromYawPitchRoll(0f, 0f, 0f); this.downOrientation = Quaternion.CreateFromYawPitchRoll(MathHelper.Pi, 0f, 0f); this.desiredOrientation = upOrientation; this.currentOrientation = this.desiredOrientation; this.desiredScale = Vector3.One; this.currentScale = this.desiredScale; this.jumpSounds = new Audio.Sfx[] { Audio.Sfx.jump1_wav, Audio.Sfx.jump2_wav, Audio.Sfx.jump3_wav }; }
// Start/stop morphing and skeletal animation. private void PlayAnimation(bool play) { if (play) { // ----- Start _morphingAnimationController = AnimationService.StartAnimation(_morphingAnimation, _sintel.MorphWeights); _skeletalAnimationController = AnimationService.StartAnimation(_skeletalAnimation, (IAnimatableProperty)_sintel.SkeletonPose); } else { // ----- Stop _morphingAnimationController.Stop(TimeSpan.FromSeconds(1)); _morphingAnimationController.AutoRecycle(); _skeletalAnimationController.Stop(TimeSpan.FromSeconds(1)); _skeletalAnimationController.AutoRecycle(); } // Disable UI controls during animation. foreach (var slider in _sliders) { slider.IsEnabled = !play; } _isPlaying = play; }
private async void TapWord(string wordName) { if (!isTapAlready) { isTapAlready = true; string compareWord = !Model.IsFromNative ? _showingWord.RusWord : _showingWord.EngWord; if (string.IsNullOrEmpty(wordName)) { return; } if (compareWord.Equals(wordName, StringComparison.OrdinalIgnoreCase)) { Model.IsOpenCurrentWord = false; SetRightMark(wordName, Color.FromHex("#6bafef")); await Task.Delay(_timeShowRightWord); } else { Model.IsOpenCurrentWord = true; SetRightMark(compareWord, Color.FromHex("#6bafef")); SetRightMark(wordName, Color.Red); Model.WordsOpen.Add(_showingWord); Model.AllOpenedWordsCount++; await Task.Delay(_timeShowMistakeWord); } ClearBackgroundColor(); await AnimationService.AnimationFade(WordContainer, 0); ShowNextWord(); await AnimationService.AnimationFade(WordContainer, 1); isTapAlready = false; } }
public static void InitShip(AnimationService animationService) { List <BezierCurve> paths = new List <BezierCurve>(); paths.Add(new BezierCurve() { StartPoint = new PointF(0, Constants.CanvasSize.Height - (Constants.SpriteDestSize.Height * 2)), EndPoint = new PointF(Constants.CanvasSize.Width, Constants.CanvasSize.Height - (Constants.SpriteDestSize.Height * 2)), ControlPoint1 = new PointF(0, Constants.CanvasSize.Height - (Constants.SpriteDestSize.Height * 2)), ControlPoint2 = new PointF(Constants.CanvasSize.Width, Constants.CanvasSize.Height - (Constants.SpriteDestSize.Height * 2)), }); var ship = new Ship() { Paths = paths, RotateAlongPath = false, Started = true, Index = -999, Visible = false }; ship.Paths.ForEach(a => { ship.PathPoints.AddRange(animationService.ComputePathPoints(a)); }); ship.Location = new PointF(0, 0); ship.LineToLocation = new System.Numerics.Vector2(0, 0); ship.CurPathPointIndex = ship.PathPoints.Count / 2; animationService.Animatables.Add(ship); }
public SkeletonMappingSample(Microsoft.Xna.Framework.Game game) : base(game) { // Get dude model and start animation on the dude. var modelNode = ContentManager.Load <ModelNode>("Dude/Dude"); _dudeMeshNode = modelNode.GetSubtree().OfType <MeshNode>().First().Clone(); _dudeMeshNode.PoseLocal = new Pose(new Vector3F(-0.5f, 0, 0), Matrix33F.CreateRotationY(ConstantsF.Pi)); SampleHelper.EnablePerPixelLighting(_dudeMeshNode); GraphicsScreen.Scene.Children.Add(_dudeMeshNode); var animations = _dudeMeshNode.Mesh.Animations; var loopingAnimation = new AnimationClip <SkeletonPose>(animations.Values.First()) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; AnimationService.StartAnimation(loopingAnimation, (IAnimatableProperty)_dudeMeshNode.SkeletonPose); // Get marine model - do not start any animations on the marine model. modelNode = ContentManager.Load <ModelNode>("Marine/PlayerMarine"); _marineMeshNode = modelNode.GetSubtree().OfType <MeshNode>().First().Clone(); _marineMeshNode.PoseLocal = new Pose(new Vector3F(0.5f, 0, 0), Matrix33F.CreateRotationY(ConstantsF.Pi)); SampleHelper.EnablePerPixelLighting(_marineMeshNode); GraphicsScreen.Scene.Children.Add(_marineMeshNode); CreateSkeletonMapper(); }
public static void DoShipExplosion(Ship ship, AnimationService animationService, GameService gameService) { if (!animationService.Animatables.Any(a => a.Sprite.SpriteType == Sprite.SpriteTypes.ShipExplosion1)) { CreateExplosion(ship, animationService, gameService); SoundManager.PlaySound(SoundManager.SoundManagerSounds.shipexplode); if (!ship.IsDoubleShip) { ship.Visible = false; } else if (ship.LeftShipHit) { ship.Location = new PointF(ship.Location.X + Constants.SpriteDestSize.Width - 3, ship.Location.Y); } } animationService.Animatables.Where(a => a.Sprite.SpriteType == Sprite.SpriteTypes.ShipExplosion1).ToList().ForEach(exp => { if (exp.SpriteBankIndex < 7) { exp.SpriteBankIndex += 1; } else { exp.DestroyImmediately = true; ship.IsExploding = false; ship.HasExploded = true; } }); }
public static void DoEnemyFire(Bug bug, AnimationService animationService, Ship ship) { List <BezierCurve> paths = new List <BezierCurve>(); paths.Add(new BezierCurve() { StartPoint = new PointF(bug.Location.X + 5, bug.Location.Y + 5), EndPoint = new PointF(ship.Location.X + 20, ship.Location.Y + 20) }); var missle = new BugMissle() { Paths = paths, DrawPath = false, PathIsLine = true, RotateAlongPath = false, Started = true, Speed = Utils.Rnd(Constants.EnemyMissileSpeed - 1, Constants.EnemyMissileSpeed + 1), DestroyAfterComplete = true }; missle.Paths.ForEach(p => { missle.PathPoints.AddRange(animationService.ComputePathPoints(p, true)); }); animationService.Animatables.Add(missle); }
public SkinnedEffectSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; GraphicsScreen.ClearBackground = true; GraphicsScreen.BackgroundColor = Color.CornflowerBlue; SetCamera(new Vector3F(1, 1, 3), 0.2f, 0); // Create a sky mesh and add an instance of this mesh to the scene. var skyMesh = ProceduralSkyDome.CreateMesh(GraphicsService, ContentManager.Load <Texture2D>("sky")); _sky = new MeshNode(skyMesh); _sky.Name = "Sky"; // Always set a name - very useful for debugging! GraphicsScreen.Scene.Children.Add(_sky); // Load the skinned model. This model is processed using the DigitalRune Model // Processor - not the default XNA model processor! // In the folder that contains dude.fbx, there are several XML files (*.drmdl and *.drmat) // which define the materials of the model. These material description files are // automatically processed by the DigitalRune Model Processor. Please browse // to the content folder and have a look at the *.drmdl and *.drmat files. var dudeModel = ContentManager.Load <ModelNode>("Dude/Dude"); dudeModel = dudeModel.Clone(); dudeModel.PoseWorld = new Pose(Matrix33F.CreateRotationY(ConstantsF.Pi)); GraphicsScreen.Scene.Children.Add(dudeModel); // The dude model consists of a single mesh. var dudeMeshNode = dudeModel.GetSubtree().OfType <MeshNode>().First(); var mesh = dudeMeshNode.Mesh; /* * // The dude mesh consists of different materials (head, eyes, torso, ...). * // We could change some of the material properties... * foreach (var material in mesh.Materials) * { * // Get all SkinnedEffectBindings which wrap the XNA SkinnedEffect. * // A material can consist of several effects - one effect for each render pass. * // (Per default there is only one render pass called "Default".) * foreach (var effectBinding in material.EffectBindings.OfType<SkinnedEffectBinding>()) * { * // We could change effect parameters here, for example: * effectBinding.PreferPerPixelLighting = true; * } * } */ // The DigitalRune Model Processor also loads animations. // Start the first animation of the dude and let it loop forever. // (We keep the animation controller to be able to stop the animation in // Dispose() below.) var timeline = new TimelineClip(mesh.Animations.Values.First()) { Duration = TimeSpan.MaxValue, LoopBehavior = LoopBehavior.Cycle, }; _animationController = AnimationService.StartAnimation(timeline, (IAnimatableProperty)dudeMeshNode.SkeletonPose); }
public override void Update(GameTime gameTime) { if (_avatarPose == null) { if (_avatarRenderer.State == AvatarRendererState.Ready) { _avatarPose = new AvatarPose(_avatarRenderer); // Start the first animation. var wrappedAnimation = WrapAnimation(_currentAvatarAnimationPreset); AnimationService.StartAnimation(wrappedAnimation, _avatarPose).AutoRecycle(); _debugRenderer.Clear(); _debugRenderer.DrawText("\n\nCurrent Animation: " + _currentAvatarAnimationPreset); } } else { if (InputService.IsPressed(Buttons.A, false, LogicalPlayerIndex.One)) { // Switch to next preset. _currentAvatarAnimationPreset++; if (!Enum.IsDefined(typeof(AvatarAnimationPreset), _currentAvatarAnimationPreset)) { _currentAvatarAnimationPreset = 0; } // Cross-fade to new animation. var wrappedAnimation = WrapAnimation(_currentAvatarAnimationPreset); AnimationService.StartAnimation(wrappedAnimation, _avatarPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.5)) ).AutoRecycle(); _debugRenderer.Clear(); _debugRenderer.DrawText("\n\nCurrent Animation: " + _currentAvatarAnimationPreset); } if (InputService.IsPressed(Buttons.B, false, LogicalPlayerIndex.One)) { // Switch to previous preset. _currentAvatarAnimationPreset--; if (!Enum.IsDefined(typeof(AvatarAnimationPreset), _currentAvatarAnimationPreset)) { _currentAvatarAnimationPreset = (AvatarAnimationPreset)EnumHelper.GetValues(typeof(AvatarAnimationPreset)).Length - 1; } // Cross-fade to new animation. var wrappedAnimation = WrapAnimation(_currentAvatarAnimationPreset); AnimationService.StartAnimation(wrappedAnimation, _avatarPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.5)) ).AutoRecycle(); _debugRenderer.Clear(); _debugRenderer.DrawText("\n\nCurrent Animation: " + _currentAvatarAnimationPreset); } } }
public static void DisableLines(AnimationService animationService) { foreach (var animatable in animationService.Animatables) { animatable.DrawControlLines = false; animatable.DrawPath = false; } }
public static void DoRecapture(Bug bug, AnimationService animationService, Ship ship) { ship.Disabled = true; if (bug.Rotation < 1500 && !bug.AligningHorizontally && !bug.AligningVertically) { //spin for a second or two bug.PathPoints.Clear(); bug.Paths.Clear(); bug.IsMoving = false; bug.RotateWhileStill = true; bug.ManualRotationRate = 15; bug.Sprite.SpriteType = Sprite.SpriteTypes.Ship; bug.Sprite.IsInitialized = false; bug.HomePoint = new Point(0, 0); SoundManager.PlaySound(SoundManager.SoundManagerSounds.fighterrescuedsong, true); } else if (!bug.IsMoving && !bug.AligningHorizontally) { //fly horizontally to align with ship bug.AligningHorizontally = true; bug.RotateWhileStill = false; bug.ManualRotationRate = 0; bug.Rotation = 0; bug.ManualRotation = 0; bug.RotateAlongPath = false; bug.Paths.Add(new BezierCurve() { StartPoint = bug.Location, EndPoint = new PointF(ship.Location.X + ship.Sprite.SpriteDestRect.Width - 3, bug.Location.Y), ControlPoint1 = bug.Location, ControlPoint2 = new PointF(ship.Location.X + ship.Sprite.SpriteDestRect.Width - 3, bug.Location.Y) }); bug.Paths.ForEach(a => bug.PathPoints.AddRange(animationService.ComputePathPoints(a, true)) ); } else if (!bug.IsMoving && !bug.AligningVertically) { bug.AligningVertically = true; //fly vertically to align with ship bug.Paths.Add(new BezierCurve() { StartPoint = bug.Location, EndPoint = new PointF(ship.Location.X + ship.Sprite.SpriteDestRect.Width - 3, ship.Location.Y), ControlPoint1 = bug.Location, ControlPoint2 = new PointF(ship.Location.X + ship.Sprite.SpriteDestRect.Width - 3, ship.Location.Y), }); bug.Paths.ForEach(a => bug.PathPoints.AddRange(animationService.ComputePathPoints(a, true)) ); } else if (!bug.IsMoving && bug.AligningHorizontally && bug.AligningVertically) { bug.DestroyImmediately = true; ship.Sprite = new Sprite(Sprite.SpriteTypes.DoubleShip); } }
public MixingSample(Microsoft.Xna.Framework.Game game) : base(game) { var modelNode = ContentManager.Load <ModelNode>("Marine/PlayerMarine"); _meshNode = modelNode.GetSubtree().OfType <MeshNode>().First().Clone(); SampleHelper.EnablePerPixelLighting(_meshNode); GraphicsScreen.Scene.Children.Add(_meshNode); var animations = _meshNode.Mesh.Animations; _runAnimation = new AnimationClip <SkeletonPose>(animations["Run"]) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; _idleAnimation = new AnimationClip <SkeletonPose>(animations["Idle"]) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Create a 'Shoot' animation that only affects the upper body. var shootAnimation = animations["Shoot"]; // The SkeletonKeyFrameAnimations allows to set a weight for each bone channel. // For the 'Shoot' animation, we set the weight to 0 for all bones that are // not descendants of the second spine bone (bone index 2). That means, the // animation affects only the upper body bones and is disabled on the lower // body bones. for (int i = 0; i < _meshNode.Mesh.Skeleton.NumberOfBones; i++) { if (!SkeletonHelper.IsAncestorOrSelf(_meshNode.SkeletonPose, 2, i)) { shootAnimation.SetWeight(i, 0); } } var loopedShootingAnimation = new AnimationClip <SkeletonPose>(shootAnimation) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Start 'Idle' animation. _idleAnimationController = AnimationService.StartAnimation(_idleAnimation, (IAnimatableProperty)_meshNode.SkeletonPose); _idleAnimationController.AutoRecycle(); // Start looping the 'Shoot' animation. We use a Compose transition. This will add the // 'Shoot' animation to the animation composition chain and keeping all other playing // animations. // The 'Idle' animation animates the whole skeleton. The 'Shoot' animation replaces // the 'Idle' animation on the bones of the upper body. AnimationService.StartAnimation(loopedShootingAnimation, (IAnimatableProperty)_meshNode.SkeletonPose, AnimationTransitions.Compose() ).AutoRecycle(); }
public PlayersModel( IEnumerable <Actor> players, MessageService messageService, AnimationService animationService) : base(players.Select(x => new PlayerModel(x, messageService))) { this.messageService = messageService; this.animationService = animationService; }
public static int CheckMissileCollisions(List <Bug> bugs, AnimationService animationService) { foreach (var missile in animationService.Animatables.Where(a => a.Sprite.SpriteType == Sprite.SpriteTypes.ShipMissle).ToList()) { var missilerect = new Rectangle((int)missile.Location.X + 5, (int)missile.Location.Y + 8, 3, 50); foreach (var bug in bugs) { var bugrect = new Rectangle((int)bug.Location.X + 5, (int)bug.Location.Y + 5, (int)bug.Sprite.SpriteDestRect.Width - 15, (int)bug.Sprite.SpriteDestRect.Height - 15); if (missilerect.IntersectsWith(bugrect)) { missile.DestroyImmediately = true; if (bug.Sprite.SpriteType == Sprite.SpriteTypes.GreenBug || bug.Sprite.SpriteType == Sprite.SpriteTypes.GreenBug_DownFlap) { bug.Sprite = new Sprite(Sprite.SpriteTypes.GreenBug_Blue); bug.SpriteBank.Clear(); bug.SpriteBank.Add(new Sprite(Sprite.SpriteTypes.GreenBug_Blue_DownFlap)); SoundManager.PlaySound(SoundManager.SoundManagerSounds.galagahit); return(0); } else { //if we've shot the captured ship then //remove it from the parent bug if that bug still exists if (bug.Sprite.SpriteType == Sprite.SpriteTypes.CapturedShip) { var b = bugs.FirstOrDefault(a => a.CapturedBug != null); if (b != null) { b.CapturedBug = null; b.CaptureState = Bug.enCaptureState.NotStarted; } } if (bug.Sprite.SpriteType == Sprite.SpriteTypes.GreenBug_Blue || bug.Sprite.SpriteType == Sprite.SpriteTypes.GreenBug_Blue_DownFlap) { SoundManager.PlaySound(SoundManager.SoundManagerSounds.galagadestroyed); } else if (bug.Sprite.SpriteType == Sprite.SpriteTypes.BlueBug || bug.Sprite.SpriteType == Sprite.SpriteTypes.BlueBug_DownFlap) { SoundManager.PlaySound(SoundManager.SoundManagerSounds.bluebughit); } else if (bug.Sprite.SpriteType == Sprite.SpriteTypes.CapturedShip) { SoundManager.StopAllSounds(); SoundManager.PlaySound(SoundManager.SoundManagerSounds.capturedfighterdestroyedsong); } else { SoundManager.PlaySound(SoundManager.SoundManagerSounds.redbughit); } bug.IsExploding = true; } return(1); } } } return(0); }