public void Update() { // Facing Camera if (Camera.main != null) { transform.position = Camera.main.transform.position + Camera.main.transform.forward * distanceToCamera; transform.forward = -(Camera.main.transform.position - transform.position); } if (currentAnimation != null) { if (timer <= currentAnimation.duration) { timer += Time.deltaTime; mask.transform.localScale = initialMaskSize * currentAnimation.curve.Evaluate(timer / currentAnimation.duration); } else { if (currentAnimation.name == "GameOver") { GameManager.instance.GoToLobby(); } else if (currentAnimation.name == "Win") { GameManager.instance.GoToWinScene(); } currentAnimation = null; } } }
//Generate new item on the field. public static void ProduceItemInField(FrameAnimation enemyAnimation, Enemy enemy, ICollection <IItem> visibleItems) { Point2D itemPosition = new Point2D(0, 0); if (enemy is Zombie) { if (enemyAnimation.SpriteEffect == SpriteEffects.None) { itemPosition = new Point2D(enemyAnimation.Position.X, enemyAnimation.Position.Y + MovingDistanceStomper); } else { itemPosition = new Point2D(enemyAnimation.Position.X + 100, enemyAnimation.Position.Y + MovingDistanceStomper); } visibleItems.Add(new Stomper("Stomper", itemPosition, OrusTheGame.Instance.Content)); } else if (enemy is Skeleton) { if (enemyAnimation.SpriteEffect == SpriteEffects.None) { itemPosition = new Point2D(enemyAnimation.Position.X, enemyAnimation.Position.Y + MovingDistanceArmour); } else { itemPosition = new Point2D(enemyAnimation.Position.X + 100, enemyAnimation.Position.Y + MovingDistanceArmour); } visibleItems.Add(new GiantArmour("GiantArmour", itemPosition, OrusTheGame.Instance.Content)); } }
/// <summary> /// 添加一个动画 /// </summary> /// <returns>动画 ID,稍后可使用该 ID 来调用相关方法设置动画</returns> /// <param name="go">对应的 gameObject</param> /// <param name="assetDir">动画资源所在目录路径(GpuAnimationWindow 中设置的 导出目录)</param> public int AddAnimation(GameObject go, string assetDir) { MeshFilter filter = go.GetComponent <MeshFilter>(); if (filter == null) { filter = go.AddComponent <MeshFilter>(); } MeshRenderer renderer = go.GetComponent <MeshRenderer>(); if (renderer == null) { renderer = go.AddComponent <MeshRenderer>(); } FrameAnimation ani = new FrameAnimation { id = ++m_id, filter = filter, renderer = renderer }; m_aniMap.Add(ani.id, ani); SetAssetDir(ani, assetDir); return(ani.id); }
void OnTriggerEnter2D(Collider2D hit) { if (hit.tag == "enemy") { Enemy enemy = hit.GetComponent <Enemy>(); if (enemy.hp <= 0) { FrameAnimation frameAnimation = hit.GetComponent <FrameAnimation>(); PolygonCollider2D pc2d = hit.GetComponent <PolygonCollider2D>(); pc2d.enabled = false; if (!frameAnimation.OnceDes) { frameAnimation.OnceDes = true; GameManager._i.score += enemy.score; } } else { enemy.hp -= 1; } Destroy(this.gameObject); } }
public void ChangeAnimation(string animationName, bool restartIfAlreadyPlaying = false) { FrameAnimation animation = GetAnimation(animationName); //Debug.Log(animationName); ChangeAnimation(animation, restartIfAlreadyPlaying); }
protected void Remove(FrameAnimation die) { if (die == anim.GetAnimation("die")) { Destroy(gameObject); } }
protected override void OnDraw(GameTime gameTime, IEnumerable <int> entityIdCollection) { float ellapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; foreach (int liveId in entityIdCollection) { FrameAnimation animation = animationComponents.GetComponentFor(liveId); Aspect aspect = aspectComponents.GetComponentFor(liveId); int frameCount = spriteMapper.GetSpriteForId(aspect.ModelNameId).FrameCount; if (animation != null) { float period = 1f / animation.FrameRate; animation.EllapsedTime += ellapsed; if (animation.EllapsedTime >= period) { animation.EllapsedTime -= period; ChooseNextFrame(animation, aspect, frameCount); } } else { ChooseNextFrame(animation, aspect, frameCount); } } }
private void SetIdleAfterAttack(FrameAnimation animation) { if (this.animation == animation) { chr.CS_SetIdle(); } }
public T_TeleEntity2D(IObject2DFactory factory, ALayer2D layer2D, T_TeleEntity entity) : base(layer2D, factory, entity) { this.Position = entity.Position; this.Rotation = entity.Rotation; this.ObjectSprite.Texture = factory.GetTextureById("TVTexture"); this.ObjectSprite.TextureRect = new SFML.Graphics.IntRect(0, 0, 86, 76); this.ObjectSprite.Origin = new SFML.System.Vector2f(this.ObjectSprite.TextureRect.Width / 2, this.ObjectSprite.TextureRect.Height / 2); SequenceAnimation sequence = new SequenceAnimation(Time.FromSeconds(20), AnimationType.LOOP); IAnimation anim = new ZoomAnimation(1, 2, Time.FromSeconds(10), AnimationType.ONETIME, InterpolationMethod.LINEAR); sequence.AddAnimation(0, anim); anim = new ZoomAnimation(2, 1, Time.FromSeconds(10), AnimationType.ONETIME, InterpolationMethod.LINEAR); sequence.AddAnimation(10, anim); anim = new FrameAnimation(new SFML.Graphics.IntRect[] { new SFML.Graphics.IntRect(0, 0, 86, 76), new SFML.Graphics.IntRect(86, 0, 86, 76) }, Time.FromSeconds(2), AnimationType.LOOP, InterpolationMethod.LINEAR); sequence.AddAnimation(10.01f, anim); this.animationsList.Add(sequence); this.PlayAnimation(0); }
//protected CS_Hitstun hitstun; public virtual void Init(Character chr) { this.chr = chr; animation = chr.Anim.GetAnimation(animationName); chr.cStates.Add(this); }
public override void Initialize(Vector2 position) { Active = true; if(cType == CrystalType.blue) { SpriteAnimation = new AnimatedSprite(Globals.content.Load<Texture2D>("Sprites/Collectables/bluerelic")); FrameAnimation relic = new FrameAnimation(1, 32, 32, 0, 0); relic.FramesPerSecond = 1; SpriteAnimation.Animations.Add("Relic", relic); } if(cType == CrystalType.red) { SpriteAnimation = new AnimatedSprite(Globals.content.Load<Texture2D>("Sprites/Collectables/redrelic")); FrameAnimation relic = new FrameAnimation(1, 32, 32, 0, 0); relic.FramesPerSecond = 1; SpriteAnimation.Animations.Add("Relic", relic); } if(cType == CrystalType.green) { SpriteAnimation = new AnimatedSprite(Globals.crysTex = Globals.content.Load<Texture2D>("Sprites/Collectables/greenrelic")); FrameAnimation relic = new FrameAnimation(1, 32, 32, 0, 0); relic.FramesPerSecond = 1; SpriteAnimation.Animations.Add("Relic", relic); } SpriteAnimation.CurrentAnimationName = "Relic"; SpriteAnimation.Position = position; collectedEffect = Globals.content.Load<SoundEffect>("Sounds/Collect_Item"); }
protected void DestroyAfterAnimation(FrameAnimation anim) { if (anim.name == explode_anim) { Destroy(gameObject); } }
public void PlayAnimationTestNotExistant() { SpriteAnimator animator = new SpriteAnimator(); FrameAnimation animation = new FrameAnimation(2f, false, 1, 10); animator.AddAnimation("test", animation); animator.PlayAnimation("wrongName"); }
public override void Init(Character chr) { base.Init(chr); chargeAnimation = chr.Anim.GetAnimation(chargeAnimationName); chr.Anim.AnimationOver += SetIdleAfterAttack; }
public void AddAnimationTestFirstAsCurrentAnimation() { SpriteAnimator animator = new SpriteAnimator(); FrameAnimation animation = new FrameAnimation(2f, false, 1, 10); animator.AddAnimation("test", animation); Assert.AreEqual(animation, animator.CurrentAnimation, "Animacija nepridėta arba sąrašas nebuvo tuščias"); }
protected override Storyboard SelectStoryboard(FrameAnimation animation) { if (animation is null) { throw new NullReferenceException(); } return(animation.Direction == AnimationDirection.Forward ? ForwardStoryboard : BackStoryboard); }
public void GetFrameTest() { FrameAnimation animation = new FrameAnimation(40.0f, true, 5, 10); int actual = animation.GetFrame(10f); int expected = 7; Assert.AreEqual(expected, actual, 0, "Nevienodi gauti frame"); }
public override void Initialize() { base.Initialize(); FrameAnimation cast = new FrameAnimation(4, 16, 16, 0, 0); cast.FramesPerSecond = 10; SpriteAnimation.Animations.Add("Cast", cast); SpriteAnimation.CurrentAnimationName = "Cast"; SpriteAnimation.Speed = 3; }
public override void Init(Character chr) { base.Init(chr); if (animationSlow != "") { fAnimSlow = chr.Anim.GetAnimation(animationSlow); } }
public PufSmoke() : base() { animation = new FrameAnimation(this); animation.Cycle = false; this.TopMostWindow = true; this.CanDrag = false; Name = "PufSmoke"; }
public override Entity Create(EntityCreateArgs args) { ParticleEmitter particleEmitter = null; string path = "../../res/particles/"; Image image; switch (args.type.ToLower()) { case "explosion": image = Image.FromFile(path + "explosion_spritesheet.png"); AnimatedSprite explosionSprite = new AnimatedSprite(image, new Vector2(), new Vector2(100, 100), 4, 4); FrameAnimation animation = new FrameAnimation(1f, false, 0, 12); particleEmitter = new AnimatedParticleEmitter(16, explosionSprite, animation, new ParticleProperties() { startSize = new Range(48, 84), startAngle = new Range(225f, 315f), startLifetime = new Range(0.75f, 1.5f), startSpeed = new Range(100f, 400f), sizeGrow = -32, }, true, ParticleEmitMode.OneShot); break; case "shield": image = Image.FromFile(path + "shield_particle.png"); Sprite shieldSprite = new Sprite(image, new Vector2(), new Vector2(100, 100)); particleEmitter = new ParticleEmitter(5, shieldSprite, new ParticleProperties() { startSize = 128f, sizeGrow = -128f, spawnRate = 0.4f, startLifetime = 1f }); break; case "health": image = Image.FromFile(path + "health_particle.png"); Sprite healthSprite = new Sprite(image, new Vector2(), new Vector2(100, 100)); particleEmitter = new ParticleEmitter(8, healthSprite, new ParticleProperties() { startSpeed = 700f, speedDamping = 0.7f, startOffset = new Vector2(20f, 0f), startSize = 64f, sizeGrow = -64f, spawnRate = 0.2f, startAngle = 270f, startLifetime = 0.5f }); break; default: return(null); } return(SceneManager.Instance.CurrentScene.CreateEntity(particleEmitter)); }
private void Remove(FrameAnimation animation) { if (animation == anim.GetAnimation("spawn")) { anim.ChangeAnimation("afterSpawn"); Instantiate(enemyGO, transform.position, Quaternion.identity); } }
public void PlayAnimationTestIfPlaying() { SpriteAnimator animator = new SpriteAnimator(); FrameAnimation animation = new FrameAnimation(2f, false, 1, 10); animator.AddAnimation("test", animation); animator.PlayAnimation("test"); Assert.IsTrue(animator.IsAnimationPlaying("test")); }
protected override void Dispose(bool disposing) { if (animation != null) { animation.Dispose(); animation = null; } base.Dispose(disposing); }
private async void SettingsButton_OnClickedAsync(object sender, EventArgs e) => await Device.InvokeOnMainThreadAsync(() => { _tableVisible = !_tableVisible; if (_heightMax == 0) { _heightMax = 680; } FrameAnimation.RunShowOrHideAnimation(SettingsTableView, _heightMax, 0, _tableVisible, false); });
// Outline: // - Each frame, it checks to see if someone is on it. If so, it's triggered. // - If it's not triggered, it advances animation to max, at a certain framerate (could use FrameAnimation) // - If it's triggered, it counts down public static void LandMineRiseFall(EntityManager em, ScriptContainer scriptContainer, int entityLiveId, GameTime gameTime) { float ellapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; bool isTriggered = scriptContainer.PropertyBag.GetBooleanValue(LandMineIsTriggeredId); if (!isTriggered) { Placement placement = (Placement)em.GetComponent(entityLiveId, ComponentTypeIds.Placement); Point spot = placement.Position.ToInteger(); MessageData data = new MessageData(spot.X, spot.Y, ComponentTypeIds.Player); em.SendMessage(Messages.QueryComponentAtGrid, ref data, null); if (data.Handled) { // Before allowing it to be triggered, the area must be cleared (so the player who dropped it doesn't trigger it) // Check to see if a Player component is on there, and if so set outselves to triggered. if (data.Int32 == EntityManager.InvalidEntityUniqueId) { // No one on it. Now it's ok to be triggered. scriptContainer.PropertyBag.SetValue(LandMineAreaClearedId, true); } bool areaCleared = scriptContainer.PropertyBag.GetBooleanValue(LandMineAreaClearedId); if (areaCleared && (data.Int32 != EntityManager.InvalidEntityUniqueId)) { // Someone is on it. isTriggered = true; scriptContainer.PropertyBag.SetValue(LandMineIsTriggeredId, isTriggered); scriptContainer.PropertyBag.SetValue(LandMineFuseCountdownId, scriptContainer.PropertyBag.GetSingleValue(LandMineFuseTimeId)); } } } Entity entity = em.GetEntityByLiveId(entityLiveId); if (isTriggered) { float timeLeft = scriptContainer.PropertyBag.GetSingleValue(LandMineFuseCountdownId); timeLeft -= ellapsed; scriptContainer.PropertyBag.SetValue(LandMineFuseCountdownId, timeLeft); if (timeLeft <= 0f) { em.SendMessage(entity, Messages.TriggerBomb, null); // BOOM } } // Move up or down based on whether we're triggered. bool allocatedNew; FrameAnimation frameAnimation = (FrameAnimation)em.AddComponentToEntity(entity, ComponentTypeIds.FrameAnimation, out allocatedNew); frameAnimation.Direction = isTriggered ? -1 : 1; frameAnimation.Loop = false; frameAnimation.FrameRate = GameConstants.LandMineAnimationFrameRate; }
IEnumerator PlayDeadAnim() { GetComponent <ParticleSystem>().Play(); yield return(new WaitForSeconds(0.5f)); FrameAnimation fa = GetComponent <FrameAnimation>(); fa.Flip(); fa.enabled = true; fa.ResetAndPlay(); }
protected void Remove(FrameAnimation animation) { FrameAnimator anim = GetComponent <FrameAnimator>(); if (anim != null) { if (animation == anim.GetAnimation("die")) { Destroy(gameObject); } } }
public override void OnInspectorGUI() { DrawDefaultInspector(); Separator(BigSeparator); frameAnimation = (FrameAnimation)target; // add action EditorGUILayout.BeginHorizontal(); GUILayout.Label("新建动画"); newAnimName = GUILayout.TextField(newAnimName); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); bool addAnim1 = GUILayout.Button("新建一阶段动画"); bool addAnim3 = GUILayout.Button("新建三阶段动画"); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("保存")) { Save(); } if (GUILayout.Button("读取")) { Load(); } EditorGUILayout.EndHorizontal(); if ((addAnim1 || addAnim3) && !frameAnimation.HasAnim(newAnimName)) { MyAnimation anim = new MyAnimation(); anim.name = newAnimName; anim.oneStage = addAnim1; frameAnimation.animations.Add(anim); } Separator(BigSeparator); DoRemoveAction(); // del action //DoRemoveAction(); for (int i = 0; i < frameAnimation.animations.Count; ++i) { MyAnimation anim = frameAnimation.animations[i]; DrawAnim(anim); } }
public void AddAnimationTestAddMultipleAnimationParametrized(int num) { SpriteAnimator animator = new SpriteAnimator(); Dictionary <string, FrameAnimation> animDict = new Dictionary <string, FrameAnimation>(); FrameAnimation[] animations = new FrameAnimation[num]; for (int i = 0; i < num; i++) { string name = "name" + i; FrameAnimation anim = new FrameAnimation(10f, false, i, 20 * i); animDict.Add(name, anim); animator.AddAnimation(name, anim); } Assert.IsTrue(animDict.All(x => animator.IsAnimationInList(x.Key) == true)); }
public override void Init(Character chr) { base.Init(chr); wallUpFA = chr.Anim.GetAnimation(wallUpAnimation); if (chr.Ctr.velocity.y > 0) { chr.Anim.ChangeAnimation(wallUpFA); } else { chr.Anim.ChangeAnimation(animation); } }
private void DrawPreviewAnimation() { GUILayout.BeginArea(previewAnimationRect); GUILayout.Space(5); if (animationIsPlaying) { GUI.color = Color.green; } if (GUILayout.Button("Play Animation")) { animationIsPlaying = !animationIsPlaying; } GUI.color = Color.white; /* * Rect previewRect = Rect.zero; * * if (currentFrame != null) * { * Vector2 position = new Vector2(20, 25); * previewRect = DrawSpriteRect(position, currentFrame.sprite, 4, blackTexture); * } * * GUILayout.Space(previewRect.height); */ GUI.color = Color.red; if (GUILayout.Button("Remove Animation")) { if (EditorUtility.DisplayDialog("Remove Animation", "Remove current animation?", "Remove", "Cancel")) { currentAnimation = null; animSO.frameAnimations.Remove(animSO.frameAnimations[currentAnimationNr]); currentAnimationNr = 0; currentFrame = null; currentFrameNr = 0; } } GUI.color = Color.white; GUILayout.EndArea(); }
public override void Initialize() { SpriteAnimation = new AnimatedSprite(Globals.content.Load<Texture2D>("Sprites/Enemies/avt3")); lifebar = Globals.content.Load<Texture2D>("HUD/rectangle"); FrameAnimation up = new FrameAnimation(2, 32, 32, 0, 0); FrameAnimation down = new FrameAnimation(2, 32, 32, 64, 0); FrameAnimation left = new FrameAnimation(2, 32, 32, 128, 0); FrameAnimation right = new FrameAnimation(2, 32, 32, 192, 0); up.FramesPerSecond = down.FramesPerSecond = left.FramesPerSecond = right.FramesPerSecond = 10; SpriteAnimation.Animations.Add("Up", up); SpriteAnimation.Animations.Add("Down", down); SpriteAnimation.Animations.Add("Left", left); SpriteAnimation.Animations.Add("Right", right); SpriteAnimation.CurrentAnimationName = "Down"; Direction = FacingDirection.Down; CollisionRadius = 64; base.Initialize(); }
public void AddFrameAnimation(string name, int fps, FrameSet set, bool loop) { if (_frameAnimations.ContainsKey(name)) { throw new ArgumentException(string.Format("Frame Animation {0} Already Exists", name)); } FrameAnimation anim = new FrameAnimation(name, _manager) { AnimationFrameSet = set, FramesPerSecond = fps, Duration = (float)(set.Count) / (float)(fps), Loop = loop, RepeatCount = loop ? int.MaxValue : 0, Apply = (v) => { if (v != null) { _frame.SourceRectangle = v.SourceRectangle; _frame.Center = v.Center; } }, // the most important part }; _frameAnimations.Add(name, anim); }
public void AddAnimation(string Name, int X, int Y, int Width, int Height, int Frames, float FrameLength, bool bIsLoopAnimation, string NextAnimation) { FrameAnimation fa = new FrameAnimation(X, Y, Width, Height, Frames, FrameLength,bIsLoopAnimation, NextAnimation); faAnimations.Add(Name, fa); iWidth = Width; iHeight = Height; v2Center = new Vector2(iWidth / 2, iHeight / 2); sCurrentAnimation = Name; faCurrAnimation = fa; }
public void PlayFrameAnimation(string name, int startIndex) { if (!_frameAnimations.ContainsKey(name)) { throw new ArgumentException(string.Format("Frame Animation {0} Doesn't Exists", name)); } if (_currentAnimation != _frameAnimations[name]) { if (_currentAnimation != null) { _currentAnimation.Stop(); } _currentAnimation = _frameAnimations[name]; _currentAnimation.Start(startIndex); } }
protected override void Initialize() { Name = "HUDScreen"; Font = Globals.content.Load<SpriteFont>("Fonts\\menufont"); ArialFont = Globals.content.Load<SpriteFont>("Fonts\\Arial"); // crystal = new AnimatedSprite(Globals.content.Load<Texture2D>("HUD/crystals")); crystal = new AnimatedSprite(Globals.content.Load<Texture2D>("Sprites/Spells/spellsprites")); FrameAnimation fire = new FrameAnimation(4, 16, 16, 0, 0); fire.FramesPerSecond = 10; crystal.Animations.Add("Fire", fire); FrameAnimation wind = new FrameAnimation(4, 16, 16, 64, 0); wind.FramesPerSecond = 10; crystal.Animations.Add("Wind", wind); FrameAnimation none = new FrameAnimation(1, 0, 0, 0, 0); none.FramesPerSecond = 0; crystal.Animations.Add("None", none); crystal.CurrentAnimationName = "None"; crystal.IsAnimating = true; crystal.Position = new Vector2(128, Globals.ScreenHeight - 32); crystal.spriteScale = 2.0f; borderTexture = Globals.content.Load<Texture2D>("HUD/border"); lifeBarTexture = Globals.content.Load<Texture2D>("HUD/rectangle"); manaBarTexture = Globals.content.Load<Texture2D>("HUD/rectangle_blue"); //don't change ANY of these values; Rectangle borderAL = new Rectangle(offset_x, offset_y - 2, maxWidth, 2); //above life Rectangle borderAM = new Rectangle(offset_x, manaStart - 2, maxWidth, 2); //above mana Rectangle borderBL = new Rectangle(offset_x, offset_y + barHeight, maxWidth, 2); //below life Rectangle borderBM = new Rectangle(offset_x, manaStart + barHeight, maxWidth, 2);//below mana Rectangle borderRL = new Rectangle(offset_x + maxWidth, offset_y, 2, barHeight); //right of life Rectangle borderRM = new Rectangle(offset_x + maxWidth, manaStart, 2, barHeight);//right of mana Rectangle borderLL = new Rectangle(offset_x - 2, offset_y, 2, barHeight); //left of life Rectangle borderLM = new Rectangle(offset_x - 2, manaStart, 2, barHeight); //left of mana BorderList = new List<Rectangle>(); BorderList.Add(borderBL); BorderList.Add(borderRL); BorderList.Add(borderAM); BorderList.Add(borderBM); BorderList.Add(borderRM); BorderList.Add(borderAL); BorderList.Add(borderLL); BorderList.Add(borderLM); }
public override void Initialize() { SpriteAnimation = new AnimatedSprite(Globals.content.Load<Texture2D>("Sprites/Player/man1")); FrameAnimation up = new FrameAnimation(2, 32, 32, 0, 0); up.FramesPerSecond = 10; SpriteAnimation.Animations.Add("Up", up); FrameAnimation down = new FrameAnimation(2, 32, 32, 64, 0); down.FramesPerSecond = 10; SpriteAnimation.Animations.Add("Down", down); FrameAnimation left = new FrameAnimation(2, 32, 32, 128, 0); left.FramesPerSecond = 10; SpriteAnimation.Animations.Add("Left", left); FrameAnimation right = new FrameAnimation(2, 32, 32, 192, 0); right.FramesPerSecond = 10; SpriteAnimation.Animations.Add("Right", right); SpriteAnimation.CurrentAnimationName = "Down"; Direction = FacingDirection.Down; selectedSpell = SelectedSpell.none; currentControlScheme = Globals.controlScheme; CheckControlScheme(); Collidable = true; CollisionRadius = 64; stopwatch = new Stopwatch(); }